Adding Users To A SharePoint 2013 Group Using CSOM

Steps
  1. Open Visual Studio in your system
  2. Select console application template and give the name as anything you like.
  3. Add a Microsoft.Client Assembly reference file in right side reference tab in Visual Studio.
  4. Replace Program.cs with the source code given below.
Code snippet
  1. using System;  
  2. using Microsoft.SharePoint.Client;  
  3.   
  4.   
  5. namespace GowthamArticles  
  6. {  
  7.     class Addusertogroup  
  8.     {  
  9.         static void Main()  
  10.         {     
  11.             ClientContext clientContext = new ClientContext("https://gowtham.sharepoint.com/tutorials");  
  12.             GroupCollection collGroup = clientContext.Web.SiteGroups;  
  13.             Group oGroup = collGroup.GetById(7);  
  14.   
  15.             UserCreationInformation userCreationInfo = new UserCreationInformation();  
  16.             userCreationInfo.Email = "[email protected]";  
  17.             userCreationInfo.LoginName = @"sp\dev";  
  18.             userCreationInfo.Title = "gowtham";  
  19.             User oUser = oGroup.Users.Add(userCreationInfo);  
  20.             clientContext.ExecuteQuery();   
  21.   
  22.               
  23.         }  
  24.     }  
  25. }   
Thanks for reading my blog. 
Ebook Download
View all
Learn
View all