Share via

TermStore class

Represents a store that contains metadata within child Group objects, TermSet objects, and Term objects.

Inheritance hierarchy


Namespace:  Microsoft.SharePoint.Taxonomy
Assembly:  Microsoft.SharePoint.Taxonomy (in Microsoft.SharePoint.Taxonomy.dll)


<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class TermStore
Dim instance As TermStore
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class TermStore


A TermStore contains zero or more Group objects, which are used to organize Terms within TermSets. Access the groups through the Groups property.

The TermStore class also provides methods for creating new child Group objects, getting and setting TermStore Administrator permissions on the term store, and checking permissions. Additionally, it provides properties that are used to get and set values of the TermStore object such as the set of working languages, and access to the keyword and orphaned term TermSet objects.

Use methods of the the TermStore class such as the GetTerms(String, Boolean) and GetTermSets(String, Int32) to search for and get TermSet and Term objects across all child groups

Finally, the TermStore provides the CommitAll() method and the RollbackAll() method to commit or roll back changes to the database These methods are the only way to persist changes to the database when updates are made in child objects such as Group, TermSet, and Term.


The following example demonstrates creating a sample term set.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
using Microsoft.SharePoint.Publishing.Navigation;

namespace NavigationDemos
    public class Class1
        public static readonly Guid NavTermSetId = new Guid("<GUID>");
        public static readonly Guid TaggingTermSetId = new Guid("<GUID>");

        //Creates the sample term set. If it exists, it will be deleted
        public static NavigationTermSet RecreateSampleNavTermSet(TaxonomySession taxonomySession, SPWeb web)
            // Use the first TermStore in the list
            if (taxonomySession.TermStores.Count == 0)
                throw new InvalidOperationException("The Taxonomy Service is offline or missing");

            TermStore termStore = taxonomySession.TermStores[0];

            // Does the TermSet already exist?
            TermSet existingTermSet = termStore.GetTermSet(NavTermSetId);

            if (existingTermSet != null)
                //If the TermSet exists, delete it.

            // Create a new TermSet
            Group siteCollectionGroup = termStore.GetSiteCollectionGroup(web.Site);
            TermSet termSet = siteCollectionGroup.CreateTermSet("Navigation Demo", NavTermSetId);
            NavigationTermSet navTermSet = NavigationTermSet.GetAsResolvedByWeb(termSet, web,
            navTermSet.IsNavigationTermSet = true;
            navTermSet.TargetUrlForChildTerms.Value = "~site/Pages/Topics/Topic.aspx";
            NavigationTerm term1 = navTermSet.CreateTerm("Term 1", NavigationLinkType.SimpleLink);
            term1.SimpleLinkUrl = "";
            NavigationTerm term2 = navTermSet.CreateTerm("Term 2", NavigationLinkType.FriendlyUrl);
            NavigationTerm term2a = term2.CreateTerm("Term 2 A", NavigationLinkType.FriendlyUrl);
            NavigationTerm term2b = term2.CreateTerm("Term 2 B", NavigationLinkType.FriendlyUrl);
            NavigationTerm term3 = navTermSet.CreateTerm("Term 3", NavigationLinkType.FriendlyUrl);
            return navTermSet;

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also


TermStore members

Microsoft.SharePoint.Taxonomy namespace