Add site administrator using C#

Here is some code to give an existing site collection user the Site Administrator level access.

string webURL = “http://testserver:12345/“;
                  using (SPSite site = new SPSite(webURL)) {
                      using (SPWeb web = site.RootWeb)
                                 SPUser user = web.SiteUsers[“domain\\UserName”];
                                 user.IsSiteAdmin = true;                             

                          catch(Exception ex)

                                    // Log exception 

Replace “domain\\UserName”, with the real domain and user name that you want to provide the Site Administrator access to.

Also,  use the SPWeb.EnsureUser method to add the user login to the site if you do not know if the user has or has not been added to the site collection.


6 Responses to Add site administrator using C#

  1. This is really fascinating, You’re an excessively professional blogger. I have joined your feed and stay up for in the hunt for more of your magnificent post. Also, I’ve shared your
    web site in my social networks

  2. Excellent blog here! Additionally your website rather a lot up very fast!
    What web host are you using? Can I get your associate
    hyperlink for your host? I wish my website loaded up as fast as yours lol

  3. It’s an remarkable article for all the web visitors; they will take advantage from it I am sure.

  4. Pearlene says:

    We stumbled over here by a different web address
    and thought I might as well check things out. I like what I see so i am just following you.
    Look forward to looking into your web page repeatedly.

  5. paypal cash says:

    What’s Happening i’m new to this, I stumbled upon this I’ve discovered It absolutely useful and it has helped me out loads. I am hoping to give a contribution & assist different users like its aided me. Great job.

  6. Erwin says:

    Good post. I will be experiencing some of these issues as well.

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 )

Google+ photo

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

Twitter picture

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

Facebook photo

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

Connecting to %s

%d bloggers like this: