Adding more than two site collection administrators programmatically.

The SiteAdministrators collection of the SPWeb object returns a SPUserCollection of all the Site Collection Administrators for the site in question.

Unfortunately, it doesn’t appear to actually allow you to “ADD” new users to the Site Collection Administrators via this collection like you can do with any other SPUserCollection for a user.

Whether it’s a bug, or not, a simple way around this is to do the following:

  1. Add the user to the site collection users list
  2. Retrieve the user you just added
  3. Set the IsSiteAdmin property for the user to true.
  4. Call SPUser.Update() for the user.

Sample code:

someSPWeb.AllUsers.Add(“domain\\user”,””,”The User”,null);

SPUser spUser = someSPWeb.AllUsers[“domain\\user”];

spUser.IsSiteAdmin = true;


Hope this helps

– Keith

12 Replies to “Adding more than two site collection administrators programmatically.”

  1. Hi.

    Thanks for this short but very usefull peace of code.

    Any idea why the spuser.update would throw an exception but the update is still completed?

  2. My sharepoint experience is limited but I can follow clear instructions.

    Can someone explain step by step how to do this without assuming any knowledge of sharepoint objects etc?


    1. this is a Great Post. I found it quickly and did not have to waste too much time trying to debug siteadministrators.add. Thanks!!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: