2

I try to remove programmatically in CSOM code the full control permission level from the OOTB sharepoint group "Owners". There is already another permissionlevel enabled before I remove the full control permission level.

I receive this error:

You cannot remove the Limited Access or Full Control permission levels.

This is my code:

private void ModifyGroup(ClientContext targetCtx, Group associatedOwnerGroup)
        {
            Microsoft.SharePoint.Client.RoleDefinition fullControlRole = targetCtx.Web.RoleDefinitions.GetByName("Full Control");
            targetCtx.Load(fullControlRole);
            targetCtx.ExecuteQuery();

            Microsoft.SharePoint.Client.RoleAssignmentCollection oRoleAssignments = targetCtx.Web.RoleAssignments;
            targetCtx.Load(oRoleAssignments);
            targetCtx.ExecuteQuery();

            foreach (var roleAssignment in oRoleAssignments)
            {
                targetCtx.Load(roleAssignment, r => r.Member, r => r.RoleDefinitionBindings);
                targetCtx.ExecuteQuery();

                if (roleAssignment.Member.Id == associatedOwnerGroup.Id)
                {
                    foreach (var roleDefinitionBinding in roleAssignment.RoleDefinitionBindings)
                    {
                        if (roleDefinitionBinding.Id == fullControlRole.Id)
                        {
                            roleDefinitionBinding.DeleteObject();
                        }
                    }
                }
            }

            targetCtx.ExecuteQuery();

        }

This is how the permissions look alike before I run the code: enter image description here

And this is a the custom permission level "Limited control 2": enter image description here

Manual in the GUI it is possible to remove the permission "Full control" from group "Owners".

  • "There is already another permission level enabled" what's this permission level? also what's the current group permission before you run your code? – Mohamed El-Qassas MVP Sep 21 '17 at 17:24
  • Please see update.. – Ola Sep 22 '17 at 9:36

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.