Dot Net Mafia

Group site for developer blogs dealing with (usually) Ionic, .NET, SharePoint, Office 365, Mobile Development, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog



Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for Ionic, SharePoint, and Office 365.

How to: Assign a Permission Level to a SharePoint Group

Earlier this week, I covered how to add a SharePoint Group to a Site Collection, but I did not cover how, you set the permission level of that group.  It's one thing to get the group added, but of course the people in that group are going to need some sort of permission to the site or site collection.  The first thing we need to do is translate one of the terms that we see in the UI to what they are called in the API.  The first thing is Permission Level.  This defines the set of permissions that can be assigned to a user or group on the site (i.e.: Read, Contribute, Full Control, etc.).  It represents a set of permssions, not just a single permission.  You can create your own permission levels as well, which I will cover in a future post.  In the API, this is called a RoleDefinition.  You can view what RoleDefinitions have been defined for your site by going to Site Settings -> Advanced Permissions -> Settings -> Permission Levels. 

To assign a permission level, we have to make use of the SPRoleAssignment class.  You get a SPRoleAssignment class by passing it a user or group  in its constructor.  This class has a collection called RoleDefinitionBindings to which you add the RoleDefinitions.  Once you assign the permission levels (or RoleDefinitions) to this RoleAssignment class, you update the site.  Here is what the code looks like.

SPRoleAssignment roleAssignment = new SPRoleAssignment(currentSiteCollection.RootWeb.SiteGroups["My Site Group"]);


roleAssignment.RoleDefinitionBindings .Add(currentSiteCollection.RootWeb.RoleDefinitions["Read"]);




In this case, I am assigning the read permission level to the group.  The reason I cover this today is that the way you assign the permission level to a group is not entirely obvious at first.  You would think you would just get a reference to the group and add the permissions to a collection.

Published Apr 02 2008, 10:11 AM by CoreyRoth
Filed under:



Rahul said:

Very helpful post.


December 2, 2009 2:41 AM

custom permission in list said:

Pingback from  custom permission in list

November 4, 2010 12:01 AM

Pam said:

THanks for the post.  Is somewhat useful but would be more so if the code wasn't cut off.  

September 15, 2011 8:53 AM

CoreyRoth said:

@Pam Sorry about that.  I reformatted the text and you should be able to see it now.

September 15, 2011 5:35 PM

Leave a Comment


About CoreyRoth

Corey Roth is an independent SharePoint consultant specializing in ECM, Apps, and Search.
2018 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems