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/sites/CSOM/");
  16. // Get the SharePoint web
  17. Web web = clientContext.Web;
  18. // Get all the site groups
  19. GroupCollection groupColl = web.SiteGroups;
  20. clientContext.Load(groupColl);
  21. // Execute the query to the server
  22. clientContext.ExecuteQuery();
  23. // Loop through all the groups
  24. foreach (Group group in groupColl)
  25. {
  26. // Display the group name
  27. Console.WriteLine(group.Title);
  28. }
  29. Console.ReadLine();
  30. }
  31. }
  32. }
Hit F5 and check the output .