Showing posts with label Managed Metadata management. Show all posts
Showing posts with label Managed Metadata management. Show all posts

Saturday, 30 July 2016

How to get all the Term from TermStore in SharePoint Using C#

Introduction
 
Retrieve all the Terms from TermStore in SharePoint Using C#, Term store management, Managed metadata.
We are fetching CustomTermset from CustomGroup.

Code
 
  1. using (SPSite RootSite = new SPSite(SPContext.Current.Site.Url))      
  2.             {      
  3.                 using (SPWeb RootWeb = RootSite.OpenWeb())      
  4.                 {      
  5.                     TaxonomySession TaxonomySession = new TaxonomySession(RootSite);      
  6.                     TermStore termstore = TaxonomySession.TermStores["Managed Metadata Service"];      
  7.                     Group group = termstore.Groups["CustomGroup"];      
  8.                     TermSet termset = group.TermSets["CustomTermset"];     
  9.                     TermCollection termcoll = termset.GetAllTerms();      
  10.                     StringBuilder strbl = new StringBuilder();      
  11.                     foreach (Term term in termcoll)      
  12.                     {      
  13.                         strbl.Append(term.Name.ToString());                              
  14.                     }      
  15.                     Literal1.Text = strbl.ToString();      
  16.               }      
  17.             }