0

After granting View/Add/Edit/Open/Delete ListItems to group on a list, the users of the group still get Access Denied when trying to access the list. Here's the code I used to grant permissions:

var group = clientContext.Web.SiteGroups.GetById(id);   
 clientContext.Load(group);
 clientContext.ExecuteQuery();  

 BasePermissions permissions = new BasePermissions();
 permissions.Set(PermissionKind.ViewListItems); 
 permissions.Set(PermissionKind.AddListItems);
 permissions.Set(PermissionKind.EditListItems);
 permissions.Set(PermissionKind.OpenItems);
 permissions.Set(PermissionKind.DeleteListItems);


 RoleDefinitionCreationInformation rdcInfo = new 
 RoleDefinitionCreationInformation();
 rdcInfo.Name = "roleDefName";
 rdcInfo.Description = "Description";
 rdcInfo.BasePermissions = permissions;
 RoleDefinition roleDefinition = 
 clientContext.Site.RootWeb.RoleDefinitions.Add(rdcInfo);

 RoleDefinitionBindingCollection RoleDefinitionBindingColl = new 
 RoleDefinitionBindingCollection(clientContext);
 RoleDefinitionBindingColl.Add(roleDefinition);

 List targetList = web.Lists.GetByTitle(listTitle);
 targetList.BreakRoleInheritance(true, false);
 RoleAssignmentCollection collRoleAssign = targetList.RoleAssignments;
 RoleAssignment rollAssign = collRoleAssign.Add(group, 
 RoleDefinitionBindingColl);

 web.RoleAssignments.Add(group, RoleDefinitionBindingColl);
 web.Update();
 clientContext.ExecuteQuery();
  • Can you check once from UI, permissions are granted for this group on list or not? Check permissions. – Ganesh Sanap Aug 19 '19 at 8:50
  • 1
    I had to add the following permissions for it for work: permissions.Set(PermissionKind.ManageLists); permissions.Set(PermissionKind.ViewFormPages); permissions.Set(PermissionKind.Open); permissions.Set(PermissionKind.ViewPages); – Bellatrix Aug 19 '19 at 11:23

Your Answer

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

Browse other questions tagged or ask your own question.