I have three lists namely X, Y and Z for which there are four different security groups called as A, B, C and D.All groups have full control to lists.My scenario is I need to break inheritance of all three lists and remove the groups C and D to have control over the lists. Security groups C and D should not have any kind of control to all the three lists.I am trying to create a feature event receiver to break inheritance .Help me out in this regards.Thanks.
-
I thing you are mixing concepts. Why do you need to break inheritance o the three lists when you say that C and D groups shouldn't have any kind of control in those lists. Why don't just removing the groups from the lists?. The other question is: Do you need a feature that when activates remove the groups C y D from the lists?– SharePointHeroCommented Sep 25, 2013 at 14:02
Add a comment
|
2 Answers
You can use the below code,
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb())
{
web.AllowUnsafeUpdates = true;
SPGroup group = web.SiteGroups["GroupName"];
SPPrincipal principal = (SPPrincipal)group;
SPRoleAssignment rAssignment = new SPRoleAssignment(group);
SPList list = web.Lists["ListName"];
//The below function Breaks the role assignment inheritance for the list and gives the current list its own copy of the role assignments
list.BreakRoleInheritance(true);
list.RoleAssignments.Remove(principal);
//update the list, so that specific group assignment will have the access.
list.Update();
web.AllowUnsafeUpdates = false;
}
}
});
Hope this helps you.
-
HI karthik how to break inheritance of a page in SharePoint programatically .For the same kind of scenario as of above i want to not allow two groups to not have permissions on particular page .how to proceed.Any help would be very helpful.Thanks Commented Sep 26, 2013 at 13:10
Here is an example code:
SPGroup group = web.SiteGroups["C"];
SPRoleDefinition fullControlDef = web.RoleDefinitions["Full Control"];
SPRoleAssignment fullControlRole = new SPRoleAssignment(group);
fullControlRole.RoleDefinitionBindings.Add(fullControlDef);
if (!list.HasUniqueRoleAssignments)
list.BreakRoleInheritance(true);
var assignmentForGroup = list.RoleAssignments.GetAssignmentByPrincipal(group);
assignmentForGroup.RoleDefinitionBindings.Remove(fullControlDef);
assignmentForGroup.Update()
-
Hi nadeem Thanks for the response but how would i remove permissions of those two groups no to have any permission on two lists .? Commented Sep 25, 2013 at 13:58
-
Check the code, it is done here: var assignmentForGroup = list.RoleAssignments.GetAssignmentByPrincipal(group); assignmentForGroup.RoleDefinitionBindings.Remove(fullControlDef); Commented Sep 25, 2013 at 14:01