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. namespace GowthamArticles
  4. {
  5. class Addusertogroup
  6. {
  7. static void Main()
  8. {
  9. ClientContext clientContext = new ClientContext("https://gowtham.sharepoint.com/tutorials");
  10. GroupCollection collGroup = clientContext.Web.SiteGroups;
  11. Group oGroup = collGroup.GetById(7);
  12. UserCreationInformation userCreationInfo = new UserCreationInformation();
  13. userCreationInfo.Email = "[email protected]";
  14. userCreationInfo.LoginName = @"sp\dev";
  15. userCreationInfo.Title = "gowtham";
  16. User oUser = oGroup.Users.Add(userCreationInfo);
  17. clientContext.ExecuteQuery();
  18. }
  19. }
  20. }
Thanks for reading my blog.