Add a user to a particular group who already exists in the site collection using Client Object Model


using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
using
Microsoft.SharePoint.Client;
namespace
ClientObjectModel
{
class Program
{
static void Main(string[] args)
{
//Add a user to a particular group who already exists in the site collection
string siteURL = "http://serverName:1111/sites/SPSiteDataQuery/";
ClientContext context = new ClientContext(siteURL);
GroupCollection groupColl = context.Web.SiteGroups;
Group group = groupColl.GetById(7);
User user = context.Web.EnsureUser(@"DomainName\UserName");
group.Users.AddUser(user);
context.ExecuteQuery();
}
}
}
Ebook Download
View all
Learn
View all