Steps
  • Open Visual Studio in your system
  • Select Console Applciation template and give as name .
  • Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
  • Replace Program.cs with the source code
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.SharePoint.Client;
  7. using System.IO;
  8. namespace CSOMCodeSamples
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. // ClientContext - Get the context for the SharePoint Site
  15. ClientContext clientContext = new ClientContext("http://gauti.sharepoint.com/sites/CSOM/");
  16. // Get the SharePoint web
  17. Web web = clientContext.Web;
  18. // Get all the site groups
  19. GroupCollection groupColl = web.SiteGroups;
  20. // Create a new site group
  21. GroupCreationInformation creationInfo = new GroupCreationInformation();
  22. creationInfo.Title = "gautiGroup";
  23. creationInfo.Description = "Custom group created using CSOM";
  24. Group newGroup = groupColl.Add(creationInfo);
  25. clientContext.Load(newGroup);
  26. // Execute the query to the server
  27. clientContext.ExecuteQuery();
  28. // Display the newly created group name
  29. Console.WriteLine(newGroup.Title + " is created successfully");
  30. Console.ReadLine();
  31. }
  32. }
  33. }
Hit f5 and check the out put in SharePoint group created successfully.