Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list (mylist) which inherits custom groups with custom permission levels from the site the list is located in.
Now I would like to change the custom permission of only one of the groups (groupToChange) and only for this specific list (mylist).

I wonder if I would get there ok with the below code:

SPList mylist = web.Lists["MyList"];<br> 
SPGroupCollection spgc = SharePointConfiguration.Site.SiteGroups;<br>
SPGroup group = spgc[groupToChange];<br>
SPRoleAssignment roleAssignment = new SPRoleAssignment((SPPrincipal)group);<br> 
mylist.Item.BreakRoleInheritance(true);<br> 
roleAssignment.RoleDefinitionBindings.Add(SharePointConfiguration.Site.RoleDefinitions["New Permission Level"]);<br>

mylist.Item.RoleAssignments.Add(roleAssignment);
mylist.Update();
share|improve this question

1 Answer 1

up vote 0 down vote accepted

In the end I solved this issue like this:

using (SPWeb web = properties.GetWeb()) { string[] grpNames = new string[3] { "Administrators", "Secretaries", "Visitors" }; string[] grpPermissions = new string[3] { "Administrator Permission", "Lists Secretary Permission", "Visitor Permission" }; SPList list = web.Lists["MyList"]; list.BreakRoleInheritance(false); while (list.RoleAssignments.Count > 0) { list.RoleAssignments.Remove(0); } for (int i = 0; i < 3; i++) { SPGroup Lgroup = web.SiteGroups[grpNames[i]]; SPRoleAssignment roleassignment_group = new SPRoleAssignment(Lgroup); roleassignment_group.RoleDefinitionBindings.Add(web.RoleDefinitions[grpPermissions[i]]); list.RoleAssignments.Add(roleassignment_group); list.Update(); } }

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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