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

Popular posts from this blog

The form cannot be submitted because of an error

Problem I created a reusable approval workflow in SharePoint Designer 2010. I initiated the workflow. Then when I filled in the Assigned To field I got an error pop up saying: "The form cannot be submitted because of an error". Solution Uninstall the KB2553322 for SharePoint Designer. I didn't uninstall KB2553322 for Microsoft Office. Restart SharePoint Designer. Recreate the workflow.

Can't read from source file or disk

When you are using Windows Explorer View in SharePoint you can't MOVE a file from one site to another if it's not directly below the root site, but you can copy the file. See the different scenarios below. Working Scenario Moving files between libraries within the same site. For example: "http://sharepointsite/sites/site1/site2/library1" (source) "http://sharepointsite/sites/site1/site2/library2" (destination) Moving files between libraries across different sites as long as they are directly below the root site. For example: "http://sharepointsite/site1/library1 (source) "http://sharepointsite/site2/library2 (destination) Non-working Scenario Moving files between libraries in sub-sites that are more than 1 level below the root site. For example: "http://sharepointsite/sites/site1/site1/library1" (source) "http://sharepointsite/sites/site1/site2/library2" (destination)

Problem installing service pack 1 for SharePoint Foundation 2010

I have a SharePoint farm with one application server, two WFE servers and one db server. When I ran the configuration wizard after I installed service pack 1 on the application server and the WFE servers I got an error that said that the service pack was missing on the WFE servers. Solution: Open your powershell editor and execute the following command on the WFE servers. Get-SPProduct –local Then run the configuration wizard again.