1

I am trying to create unique permission in a SharePoint list using client side C# code. I am able to break inheritance and add a permission level to the group, but the thing is it is getting added to the permission level. For example if i have an owner group and I have full control from the site, once i break permission for a list and assign read permission to the Owner group, I get both Full Control and Read permission for the group. I would like to know if there is a way if i can remove all the permission from the group before adding my own groups and permisssion. below is the code:

 public static void AddPermission(ClientContext cpx, List list, string groupName, RoleDefinition rdef)
 {
  try {
   var GRoup1 = cpx.Web.SiteGroups.GetByName(groupName);
   list.BreakRoleInheritance(true, false);
   list.Update();
   cpx.Load(list);
   cpx.ExecuteQuery();
   RoleDefinitionBindingCollection collRoleDefinitionBinding = new RoleDefinitionBindingCollection(cpx);
   collRoleDefinitionBinding.Add(rdef);
   list.RoleAssignments.Add(GRoup1, collRoleDefinitionBinding);
   cpx.ExecuteQuery();
  } catch (Exception ex) {

  }
 }
2

Delete the group and then add it back,

list.RoleAssignments.GetByPrincipal(GRoup1).DeleteObject();

add above code after breaking permission and before updating list.

Your code will be as

var GRoup1 = cpx.Web.SiteGroups.GetByName(groupName);
list.RoleAssignments.GetByPrincipal(GRoup1).DeleteObject();
list.BreakRoleInheritance(true, false);

try and let me know if it helps.

  • 1
    i tried list.BreakRoleInheritance(false, true) and it worked!!!!! – Ankit Kumar Jan 19 '16 at 14:31
2

modified the list.BreakRoleInheritance as list.BreakRoleInheritance(false,true); and it worked!!!

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.