How to get all the groups for the termstore

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.   
  16.             ClientContext clientContext = new ClientContext("http://servername/sites/CSOM/");  
  17.             // Get the TaxonomySession    
  18.             TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);  
  19.             // Get the term store by name    
  20.             TermStore termStore = taxonomySession.TermStores.GetByName("GVR");  
  21.             // Get all the groups for the term store    
  22.             clientContext.Load(termStore.Groups,  
  23.             termGroups = > termGroups.Include(termGroup = > termGroup.Name));  
  24.             // Execute the query to the server    
  25.             clientContext.ExecuteQuery();  
  26.             // Loop through all the termgroup for the termstore    
  27.             foreach(TermGroup group in termStore.Groups)   
  28.             {  
  29.                 // Display the group name    
  30.                 Console.WriteLine(group.Name);  
  31.             }  
  32.             Console.ReadLine();  
  33.         }  
  34.     }  
  35. }    
Hit F5 and check the output.
Thanks for learning my blogs!!!