Introduction
Retrieve all the Terms from TermStore in SharePoint Using C#, Term store management, Managed metadata.
We are fetching CustomTermset from CustomGroup.
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();
- }
- }
No comments:
Post a Comment