How to Add Users to a Group in Sharepoint 2010

Code snippets for how to add users in groups in various object models of Sharepoint.

Server Object Model -

Adding users to your new group -

SPUser spUser = spWeb.EnsureUser("domain\isha");

if (spUser != null)
SPGroup spGroup = spWeb.Groups["Mygroup"];

if (spGroup != null)

Using Silverlight Client Object model -

ClientContext ctx = new ClientContext("http://SPsite");
Group membersGroup = ctx.Web.AssociatedMemberGroup;

// Add existing user to membersGroup
User currentUser = membersGroup.Users.AddUser(ctx.Web.CurrentUser);

// Add new user to membersGroup
UserCreationInformation userCreationInfo = new UserCreationInformation();
userCreationInfo.Email = "";
userCreationInfo.LoginName = @"domain\isha";
userCreationInfo.Title = "Isha Attlee";
User newUser = membersGroup.Users.Add(userCreationInfo);

.Net Managed Client Object model -

ClientContext ctx = new ClientContext(“http://SPSite”);

//get the group
Group grp = ctx.Web.SiteGroups.GetById(GroupId);

//create the user object
UserCreationInformation usr = new UserCreationInformation();

usr.LoginName = “Domain\isha”;

usr.Email = “”;

usr.Title = “Programmer”;

//add it to the group

//execute the query to add the user


Post a Comment


This is a personal weblog. The opinions expressed here represent my own and not those of my employer or anyone else. Should you have any questions or concerns please e-mail me at .

Copyright (c) 2010 @ All rights are reserved.Do Not Copy.

@ Learning