Using SharePoint Web Services to Change Subsite Permissions
page 3 of 5
by Grant Zhang
Feedback
Average Rating: 
Views (Total / Last 10 Days): 64540/ 100

Add Role and Add User to This Role

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.

 


View Entire Article

User Comments

Title: SoapServerException   
Name: Raj
Date: 2009-05-26 2:28:10 AM
Comment:
good artical
Title: SoapServerException   
Name: Grant Zhang
Date: 2008-11-06 8:59:26 AM
Comment:
\
\
Title: SoapServerException   
Name: Srinivas Reddy
Date: 2008-11-06 7:23:25 AM
Comment:
\
Title: Reply to Get a Exception on AddRole   
Name: Grant Zhang
Date: 2007-09-05 9:15:04 AM
Comment:
Check details in SoapException and you'll find teh real reason why it failed.
Title: Get a Exception on AddRole   
Name: Dinesh Chaudhari
Date: 2007-09-05 8:54:07 AM
Comment:
Hello ,
This article is very nice to learn SP webservices. I tired the sample with making necessary changes .But i got following Exception :So can you tell me where I go wrong or is there any setting i need to do for removing this exception .I am waiting for reply:
My Conatact Email id: dinchaudhari@gmail.com

Role Manager can not be added to the site: http://ps2454:41300/1100. The error: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.

The permissions can not be updated for http://ps2454:41300/1100. The error: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.

The permissions can not be updated for http://ps2454:41300/1100. The error: Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
Title: Using SharePoint Web Services to Change Subsite Permissions   
Name: nak
Date: 2007-06-14 7:24:44 AM
Comment:
good article.
I like it
Title: This Approach is not for MOSS 7   
Name: Sourabh
Date: 2007-06-08 11:14:53 AM
Comment:
Hi all this is not a supported modal for MOSS 7 or sharepoint 2007 instead use the roledefinition as the permission is depricated.
Title: Good Article   
Name: Prasant
Date: 2007-05-23 7:28:18 AM
Comment:
Thanks.. It is working. I was using "AddUserToGroup"..

Thanks again
Title: Good Article   
Name: Prasant
Date: 2007-05-23 7:24:11 AM
Comment:
I have one question:
I am trying to add user to "Contributor" Site group.but it gives error that "Cross-site group cannot be found".

How we can add user to built-in site groups.

Thanks
Title: Excellent Article   
Name: Anil
Date: 2006-12-27 9:43:40 AM
Comment:
Excellent article,this helped me a lot in getting started with Sharepoint web services.Example is too.. good.
Title: Very useful article   
Name: Anupam
Date: 2006-04-05 7:43:36 AM
Comment:
Helped a lots in getting us started with Sharepoint web services.
Title: Useful but   
Name: Anvar
Date: 2006-04-04 3:38:29 AM
Comment:
HI this is a useful and great article.
Will you please give what are parametrs are there in network credential information. Even i am having administrator power i t is not allowing me to get in. please help me.
Title: Great Article   
Name: Niels Hansen
Date: 2006-03-25 8:27:26 PM
Comment:
Great Article. This is exactly the information I was looking for. Please do more on how to progamatically use SPS.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-12-11 7:55:42 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search