I am having various site collections and I want to add few users into administrator group. So that more people will have access to edit the groups. I can add users to the site collection administrators group through Site Actions -> Site Collection Administrators (and add users)

But I want to add users into admin group through code? I didn't get much idea about it.

Any help is appreciated.


3 Answers 3


There is a big difference with being site collection administrator. While the answer by MBsurf makes a user site admin, that will give him probably to much permissions. Using the code below you can retrieve the Owners group of a site and then add a user to that group:

// get the owners group based on permission
var ownerAssignment = (from a in site.RootWeb.RoleAssignments.OfType<SPRoleAssignment>() 
where a.RoleDefinitionBindings.OfType<SPRoleDefinition>().
select a).FirstOrDefault();

// get the assignment's SharePoint group
var adminGroup = (SPGroup)ownerAssignment.Member;
// you can now add a user to this group
  • Agreed. Much of the time Site Collection admin rights are probably too much. However, Ankit requested the user be able to edit group membership.
    – MBSurf
    Commented Jun 7, 2011 at 13:17
  • Thanks for your solution. I will try this and will update about my findings :) Thanks again.. :)
    – Ankit
    Commented Jun 7, 2011 at 13:44

Check out this post.

Here is the example from the post:

//if the user is not a user on the site already
someSPWeb.AllUsers.Add(“domain\\user”,”[email protected]”,”The User”,null);

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

spUser.IsSiteAdmin = true;

  • Good answer, but please remember that external links tend to die. Since we plan to stay in business for quite a while, it would be great if you could extend your answer with the code sample in the external link. Thank you! Commented Jun 7, 2011 at 13:01
  • 4
    You can replace the first two lines by : SPUser spUser = someSPWeb.EnsureUser("domain\\user").
    – Steve B
    Commented Jun 7, 2011 at 13:44

The below property is more effective to retrieve the site (SPWeb) owner group:




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.