Steps
  1. Open Visual Studio in your system.
  2. Select Console Applciation template and give as name.
  3. Add a Microsoft.Cleint Assembly refrence file in right side refrence tab in visual studio.
  4. 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 Microsoft.SharePoint.Client.Taxonomy;
  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://servername/sites/CSOM/");
  16. // Get the TaxonomySession
  17. TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
  18. // Get the term store by name
  19. TermStore termStore = taxonomySession.TermStores.GetByName("GVR");
  20. // Get all the groups for the term store
  21. clientContext.Load(termStore.Groups,
  22. termGroups = > termGroups.Include(termGroup = > termGroup.Name));
  23. // Execute the query to the server
  24. clientContext.ExecuteQuery();
  25. // Loop through all the termgroup for the termstore
  26. foreach(TermGroup group in termStore.Groups)
  27. {
  28. // Display the group name
  29. Console.WriteLine(group.Name);
  30. }
  31. Console.ReadLine();
  32. }
  33. }
  34. }
Hit F5 and check the output.
Thanks for learning my blogs!!!