Skip to main content

Adding Site Administrators to a Site Collection


If you want to add a SiteAdministrator to a SiteCollection you can't add the user to the SPUserCollection SPWeb.SiteAdministrators.
SPWeb.SiteAdministrators.Add()
SPUserCollection SPWeb.SiteAdministrators is of type SPUserCollectionType.UCT_SiteAdmins (6), which appears that SharePoint is not taking care of.
If it's a bug, i don't know.

Instead you have to set the property IsSiteAdmin of the SPUser to True;
SPWeb web = SPContext.Current.Web;
SPUser user = web.AllUsers["loginName"];
user.IsSiteAdmin = true;
user.Update();

Comments

  1. Can I do this via REST API or any webservice? I'm using Office365, and I need to add a user (who is NOT a site user) as Site Collection Admin on the OneDrive (my site) for another tenant user. I can do this via Powershell but I wish to achieve this through APIs. How can I achieve this?

    ReplyDelete

Post a Comment