SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know how to grant someone certain role to a list (contribute or read for example) using C# such as:

                    SPRoleAssignment userRoleAssignmentCont = new SPRoleAssignment(allUsers);
                    SPRoleDefinition userRoleDefinitionCont = web.RoleDefinitions["Contribute"];

But how do I do the exact same thing but instead of the list I grant permission to a group of people/permissions list. So basically - the user/users in question will be granted contribute permissions to add, remove or update people to a certain group (special administrators for example).

share|improve this question
up vote 1 down vote accepted

Hope this helps!

public void addPermissionToGroup()
    SPSite site = new SPSite("http://mysite:5050/");
    SPWeb spWeb = site.OpenWeb();
    string permissionName = "Read";
    string groupName = "Project Manager";

    spWeb.AllowUnsafeUpdates = true;
    SPRoleAssignment roleAssignment = new SPRoleAssignment(spWeb.SiteGroups[groupName]);

    if (!spWeb.HasUniqueRoleAssignments)

catch (Exception _exception)
    throw _exception;
    spWeb.AllowUnsafeUpdates = false;

For adding user to Group:

public void AddUsers(string groupname, string username)
           // Gets a new security context using SHAREPOINT\system
           using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                 using (SPWeb thisWeb = site.OpenWeb())
                      thisWeb.AllowUnsafeUpdates = true;
                      SPUser Name = thisWeb.EnsureUser(username);
                      thisWeb.AllowUnsafeUpdates = false;


 catch (Exception ex)
   //Log error here.

Set GroupA as owner of GroupB

  using (SPSite site = new SPSite("http://site02"))
  using (SPWeb web = site.OpenWeb())
    web.AllowUnsafeUpdates = true;
   SPGroup visitors = web.SiteGroups["GroupB"];
   SPGroup members = web.SiteGroups["GroupA"];
   visitors.Owner = (SPMember)members;
   web.AllowUnsafeUpdates = false;
share|improve this answer
Sorry, my explanation was possibly wrong. I want to give a user permission to manage user groups (add users to a particular group etc.) – JᴀʏMᴇᴇ Nov 5 '12 at 10:06
Please look the edited answer here you have to pass username, and group. – Anuja Nov 5 '12 at 10:14
another solution could be by "/UserGroup.asmx" also. – Anuja Nov 5 '12 at 10:15
This still hasn't really addressed my initial problem. Thanks a lot for your help so far but what I'm looking to do is give a user group permission to manage a user group. So if I belong to GroupA - I am permitted to add/remove/update users belonging to GroupB. – JᴀʏMᴇᴇ Nov 5 '12 at 10:19
ok, I got your question, for that you have to set the GroupB owner property with the name of GroupA. Editing my answser with code. – Anuja Nov 5 '12 at 10:31

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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