0

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(); 

1 Answer 1

0

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(); } }

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.