Search This Blog

Showing posts with label Add users to the sharepoint group using csom. Show all posts
Showing posts with label Add users to the sharepoint group using csom. Show all posts

Sunday, March 26, 2017

Add Users to Sharepoint Group in SharePoint 2013 using CSOM

 using(ClientContext clientContext = new ClientContext("http://Test.sharepoint.com/sites/TestSite/"))
 {
            GroupCollection Groups = context.Web.SiteGroups;
            //Get the group by its name 
            Group ownersGroup = Groups.GetByName("GroupName");
            // Create the new user info  
            UserCreationInformation userCreationInfo = new UserCreationInformation();
            userCreationInfo.Email = "Parthasarathy@sharepoint.com";
            userCreationInfo.LoginName = "sharepoint\\Parthasarathy";
            userCreationInfo.Title = "User";  
            // Add the user to the group  
            User newUser = ownersGroup.Users.Add(userCreationInfo);
            context.ExecuteQuery();
 }