SharePoint has built-in groups Guest, Reader, Contributor,
Web Designer, and Administrator with default site permissions, but you can add your
own groups with customized permissions on the site and on specific lists.
The Users and Groups service of SharePoint provides methods
for working with users, site groups, and cross-site groups. The Web Reference
is: http://Server_Name/[sites/][Site_Name/]_vti_bin/UserGroup.asmx.
The Users and Groups service has over thirty methods. It
contains all the web methods to work with groups, roles, and users. The AddUserToRole
method is used to add a user to a specific role and AddRole web method is what
we need here to add the manager role to each subsite, Listing 2 shows the code
for adding the manager role.
The AddRole web method has three input parameters. The first
two parameters are straightforward. The third parameter is defined on the
Microsoft web site as shown in Table 1.
·
roleName A string that contains the name of the site
group.
·
description A string that contains the description
for the site group.
·
permissionMask A 32-bit integer in 0x00000000 format
that represents a Microsoft.SharePoint
.SPRights value and specifies permissions for the new site group. Use the
pipe symbol ("|") in C# or Or in Visual Basic .NET to delimit values
when creating a custom permission mask that combines permissions.
Listing 2 – Add manager role and add a user to
Manager role
ws_usergroup.UserGroup ws = newws_usergroup.UserGroup();
ws.Url = sOneSubSite +"/_vti_bin/usergroup.asmx";
NetworkCredential nc = newNetworkCredential(sUserName, sPassword, sDomain);
ws.Credentials = nc;
ws.AddRole("Manager", "Managerrole.", 0x00000400|0x00000800);
ws.AddUserToRole("Manager","",@"us\grant", "","");
Table 1 - SPRights Enumeration
Name
|
Value
|
Description
|
AddAndCustomizePages
|
0x00040000
|
Add, change, or delete ASPX pages, HTML pages, or Web Part
Pages, and edit the Web site using a Windows SharePoint Services-compatible
editor.
|
AddDelPrivateWebParts
|
0x10000000
|
Add or remove Web Parts on a personalized Web Part Page.
|
AddListItems
|
0x00000002
|
Add items to lists, add documents to document libraries,
and add Web discussion comments.
|
ApplyStyleSheets
|
0x00100000
|
Apply a style sheet (.CSS file) to the Web site.
|
ApplyThemeAndBorder
|
0x00080000
|
Apply a theme or borders to the entire Web site.
|
BrowseDirectories
|
0x04000000
|
Browse directories in a Web site.
|
BrowseUserInfo
|
0x08000000
|
View information about users. This right is not available
through the user interface.
|
CancelCheckout
|
0x00000100
|
Check in a document without saving the current changes.
|
CreatePersonalGroups
|
0x01000000
|
Create, change, and delete site groups, including adding
users to the site groups and specifying which rights are assigned to a site
group.
|
CreateSSCSite
|
0x00400000
|
Create a Web site using Self-Service Site Creation.
|
DeleteListItems
|
0x00000008
|
Delete items from a list, documents from a document
library, and Web discussion comments in documents.
|
EditListItems
|
0x00000004
|
Edit items in lists, edit documents in document libraries,
edit Web discussion comments in documents, and customize Web Part Pages in
document libraries.
|
EmptyMask
|
0x00000000
|
Has no permissions on the Web site. Not available through
the user interface.
|
FullMask
|
-1
|
Has all permissions on the Web site. Not available through
the user interface.
|
ManageListPermissions
|
0x00000400
|
Grant, deny, or change user permissions to a list.
|
ManageLists
|
0x00000800
|
Approve content in lists, add or remove columns in a list,
and add or remove public views of a list.
|
ManagePersonalViews
|
0x00000200
|
Create, change, and delete personal views of lists.
|
ManageRoles
|
0x02000000
|
Create, change, and delete site groups, including adding
users to the site groups and specifying which rights are assigned to a site
group.
|
ManageSubwebs
|
0x00800000
|
Manage or create sub sites.
|
ManageWeb
|
0x40000000
|
Manage a site, including the ability to perform all
administration tasks for the site and manage contents and permissions
|
OpenWeb
|
0x00010000
|
Open the SharePoint Web site and get metadata related to
the site, as well as see the underlying navigation structure (not exposed in
the user interface).
|
UpdatePersonalWebParts
|
0x20000000
|
Update Web Parts to display personalized information.
|
ViewListItems
|
0x00000001
|
View items in lists, documents in document libraries, view
Web discussion comments, and set up e-mail alerts for lists.
|
ViewPages
|
0x00020000
|
View pages in a Web site.
|
ViewUsageData
|
0x00200000
|
View reports on Web site usage.
|