Access Term Store Programmatically


To get the term store or term set or term, you need to get the TaxonomySession first.  You also need to reference Microsoft.SharePoint.Taxonomy namespace


using (SPSite site = new SPSite (""))
{
   TaxonomySession taxonomySession = new TaxonomySession(Site);

   //get the default one
   TermStore termStore = taxonomySession.DefaultSiteCollectionTermStore;
   /* or you can get the one you want by looping through all the term stores
     taxonomySession.TermStores
   */

   Group group = termStore.Groups["groupName"];

   TermSet termSet = group.TermSets["TermSetName"];

   //you can further looping through all the terms in the term set
   TermCollection terms = termSet.Terms
   Term term = terms[0];

//For the term that has multiple languages, you can get the label in the specific language by passing in the LCID.
   term.GetDefaultLabel(1033);
}



Comments

Popular posts from this blog

SharePoint 2013 App Details Page Error

SharePoint 2013 - Working with Display Template for Content Search Web Part

Add spell check dictionary in SharePoint 2010, SharePoint 2013, and Office 365