Introduction
This post shows how to retrieve all the Terms from the Term Store in SharePoint Using C#. We are fetching a custom Term Set from a Custom Group.
Code:
- using (SPSite RootSite = new SPSite(SPContext.Current.Site.Url))
- {
- using (SPWeb RootWeb = RootSite.OpenWeb())
- {
- TaxonomySession TaxonomySession = new TaxonomySession(RootSite);
- TermStore termstore = TaxonomySession.TermStores["Managed Metadata Service"];
- Group group = termstore.Groups["CustomGroup"];
- TermSet termset = group.TermSets["CustomTermset"];
- TermCollection termcoll = termset.GetAllTerms();
- StringBuilder strbl = new StringBuilder();
- foreach (Term term in termcoll)
- {
- strbl.Append(term.Name.ToString());
- }
- Literal1.Text = strbl.ToString();
- }
- }