using (SPSite site = (SPSite)properties.Feature.Parent)
   using (SPWeb web = site.OpenWeb())
        if (web != null)
          web.AllowUnsafeUpdates = true;
          SPList list = web.Lists["Alert Status v1.0"];

          //Creates a new role assignment for a group
          SPGroup myGroup = web.SiteGroups["IKM Manager"];
          SPRoleAssignmentCollection roleAssignments = web.RoleAssignments;

          // SPRoleAssignment accepts a SPPrincipal which can be a SPUser or SPGroup
          SPRoleAssignment roleAssignment = new SPRoleAssignment(myGroup);

          //Add the new role assignment to the collection of role assignments for the site.

          // Stop inheriting permissions

I have error on RoleAssignments.Add(roleAssignment) like "Cannot add a role assignment with empty role definition binding collection". I want to stop inheriting permissions and add specific group to List permissions. Can you help me? please..


You need to define the role (as in what level of permission to grant the group).

The class is SPRoleDefinition.

SPRoleAssignment roleAssignment = new SPRoleAssignment(myGroup);
SPRoleDefinition roleDefinition = web.RoleDefinitions.GetByType(SPRoleType.Administrator);

See: https://stackoverflow.com/questions/358647/programatically-add-user-permission-to-a-list-in-sharepoint

| improve this answer | |
  • thank you for your answer but normally I have IKM Manager group which is in root site permission, has Full Control. My list is inheriting permissions. I want to stop inheritance and set the just IKM Manager group to my list. So, I need to know that do I have to set roledefinition to this group? because it is defined already!! – mkacar Aug 1 '12 at 20:55
  • I updated my post to reflect this. It's two lines of code between your two lines. SPRoleType.Administrator is Full Control in this respect. – RJ Cuthbertson Aug 2 '12 at 12:42

1) You need to use list.BreakRoleInheritance(false). Using true copies the existing role assignments to the list - so everyone who had access to the site would continue to have access to the list. Using false clears any role assignments - so nobody has any access, until you add your new one.

2) As mentioned above, you have to use a Role Definition to assign how much access a particular Role Assignment provides.


The SPRoleType enumeration provides a shortcut to the predefined permissions levels. You can also set rights individually for a Role Definition using it's BasePermissions.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.