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)
                      {
                           try
                           {
                                 SPUser user = web.SiteUsers[“domain\\UserName”];
                                 user.IsSiteAdmin = true;                             
                                 user.Update();            
                          }

                          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.