Hi ,
I'm looking for CSOM API or sample code snippet for updating User Roles for a Site Collection
Tenant Admin URL: https://<tenant>-admin.sharepoint.com
SP URL : https://<tenant>.sharepoint.com/Sites/SiteCollection1
Technologies using: C#, CSOM API for ShrarePoint Communication
From Sharepoint UI:
I can update user role Definition from UI
Things I tried using CSOM API:
- Logged into above mentioned SP tenant admin URL using admin account (URL: https://<tenant>-admin.sharepoint.com)
- Using Site Collection URL (https://<tenant>.sharepoint.com/sites/SiteCollection1), tried changing/Updating User Roles Definitions
- Same code works fine that is can Successfully update User Role Definitions for SubSite (URL: https://<tenant>.sharepoint.com/Sites/SiteCollection1/SubSite-A1)
Error/Exception :
Cannot change permissions of root web: https://<tenant>.sharepoint.com/Sites/SiteCollection1
Code Snippet for Quick Reference
SP.RoleDefinitionBindingCollection collRoleDefinitionBinding = new SP.RoleDefinitionBindingCollection(this);
SP.RoleDefinition roletypes = this.Web.RoleDefinitions.GetByType("Editor");
collRoleDefinitionBinding.Add(roletypes);
spOClientContext.Web.RoleAssignments.Add(checkuser, collRoleDefinitionBinding);
spOClientContext.ExecuteQuery();
Thanks,