Term Class


Represents a Term or a Keyword in a managed metadata hierarchy.

public ref class Term sealed : Microsoft::SharePoint::Taxonomy::TermSetItem
[Microsoft.SharePoint.Client.ClientCallableType(ClientLibraryTargets=Microsoft.SharePoint.Client.ClientLibraryTargets.NonRESTful, FactoryType=typeof(Microsoft.SharePoint.Taxonomy.Internal.TaxonomyClientObjectFactory), ObjectIdentityPropertyName="CanonicalId", ServerTypeId="5B8C81B7-7CD2-40dc-8525-5ECA12A4EB73")]
public sealed class Term : Microsoft.SharePoint.Taxonomy.TermSetItem
type Term = class
    inherit TermSetItem
Public NotInheritable Class Term
Inherits TermSetItem


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Globalization;
using System.Security.Principal;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;

namespace Microsoft.SDK.SharePoint.Samples
    class Program
        static void Main(string[] args)
            if (args.Length < 1)
                Console.WriteLine("Please add site url as an argument");
            SPSite site = new SPSite(args[0]);
            if (site != null)
                TermStore termStore = GetATermStore(site);

                if (termStore != null)
                    // creat a group
                    Group group = termStore.CreateGroup("TestData");

                    // test term properties
                    TestTermCodeSamples.TestTermProperties(termStore, group);
                    // test child terms and sort order
                    TestTermCodeSamples.TestGetTerms(termStore, group);
                    // test term operation
                    TestTermCodeSamples.TestTermOperation(termStore, group);

        static TermStore GetATermStore(SPSite site)
            // Get a TaxonomySession from the site
            TaxonomySession session = new TaxonomySession(site);
            TermStore termStore = null;
            // Get a TermStore from the session
            if (session.TermStores != null && session.TermStores.Count > 0)
                termStore = session.TermStores[0];
            return termStore;

    static class TestTermCodeSamples
        public static void TestGetTerms(TermStore termStore, Group group)
            if (termStore == null)
                throw new System.ArgumentNullException("termStore");
            if (group == null)
                throw new System.ArgumentNullException("group");

            // get current thread lcid
            int lcid = CultureInfo.CurrentCulture.LCID;

            // create term set
            TermSet termSet = group.CreateTermSet("Month");

            // TermSetItem.DoesUserHavePermission method
            // check if the current user has permission to edit the term set
            bool doesUserHavePermission = termSet.DoesUserHavePermissions(TaxonomyRights.EditTermSet);
            Console.WriteLine("The current user " +
                WindowsIdentity.GetCurrent().Name.ToString() +
                (doesUserHavePermission?" has":" does not have") +
                " permission to edit the term set.");

            // create term
            // TermSetItem.CreateTerm(System.String,System.Int32)
            Term term = termSet.CreateTerm("Week", lcid);

            // Create terms
            Term termFri = term.CreateTerm("Fri", lcid);
            Term termMon = term.CreateTerm("Mon", lcid);
            Term termSat = term.CreateTerm("Sat", lcid);
            Term termSun = term.CreateTerm("Sun", lcid);
            Term termThu = term.CreateTerm("Thu", lcid);
            Term termTue = term.CreateTerm("Tue", lcid);
            Term termWed = term.CreateTerm("Wed", lcid);

            // print each term name and id

            // define a custom sort order
            // Term.CustomSortOrder
            term.CustomSortOrder = termSun.Id.ToString() + ":" + 
                termMon.Id.ToString() + ":" +
                termTue.Id.ToString() + ":" +
                termWed.Id.ToString() + ":" +
                termThu.Id.ToString() + ":" +
                termFri.Id.ToString() + ":" +

            // commit term store changes

            // print child terms with paging of 5
            // TermSetItem.GetTerms(int)
            TermCollection retrievedTerms = term.GetTerms(5);

            // get term starts with 'S'
            // Term.GetTerms
            retrievedTerms = term.GetTerms("S", lcid,
                true /* search default label only */,
                5, /*maximum results returned*/
                true /*trim term that is not available for tagging */);

        public static void TestTermOperation(TermStore termStore, Group group)
            if (termStore == null)
                throw new System.ArgumentNullException("termStore");
            if (group == null)
                throw new System.ArgumentNullException("group");

            // get current thread lcid
            int lcid = CultureInfo.CurrentCulture.LCID;

            // create term sets and terms
            TermSet termSetA = group.CreateTermSet("A");
            TermSet termSetB = group.CreateTermSet("B");

            Term termA1 = termSetA.CreateTerm("A1", lcid);
            Term termA2 = termSetA.CreateTerm("A2", lcid);
            Term termB1 = termSetB.CreateTerm("B1", lcid);
            Term termB2 = termSetB.CreateTerm("B2", lcid);

            // Copy, created new term "Copy of A1" under the same parent

            // Move, term "A1" is moved to term set "B"

            // Reuse, term "B2" is reused as a child term of term "A2"
            Term reusedCopyofTermB2 = termA2.ReuseTerm(termB2, false);
            // then re-assign source term to the reused copy under term "B2"

            // Merge, merge "A1" to "A2", the new merged term is called "A2", 
            // and is reused under both term set "A" and "B"
            Term mergedTerm = termA1.Merge(termA2);

            // Print merged term information
            Console.WriteLine("Merged Terms:");
            Console.WriteLine("Term: " + mergedTerm.Name + ", IsSource: " + 
                mergedTerm.IsSourceTerm + ", Term Set:" + mergedTerm.TermSet.Name);
            foreach (Term term in mergedTerm.ReusedTerms)
                Console.WriteLine("Term: " + term.Name + ", IsSource: " +
                    term.IsSourceTerm + ", Term Set:" + term.TermSet.Name);
            // Print merged term Ids
            foreach (Guid id in mergedTerm.MergedTermIds)
                Console.WriteLine("MergedId: " + id);


        public static void TestTermProperties(TermStore termStore, Group group)
            if (termStore == null)
                throw new System.ArgumentNullException("termStore");
            if (group == null)
                throw new System.ArgumentNullException("group");

            // get current thread lcid
            int lcid = CultureInfo.CurrentCulture.LCID;

            TermSet termSet = group.CreateTermSet("Term Set");
                Term term = termSet.CreateTerm("Term1", lcid, Guid.NewGuid());

                // Set Description and label
                term.SetDescription("This is the description for the term.", lcid);
                term.CreateLabel("Term Label 1", lcid, false);


                Console.WriteLine("Term description: " + term.GetDescription());
                Console.WriteLine("Term default label: " + term.GetDefaultLabel(lcid));

                // print all term labels for an lcid, include both default and 
                // non-default label
                LabelCollection labels = term.GetAllLabels(lcid);
                foreach (Label label in labels)
                    Console.WriteLine("Term label " + label.Value);

                Console.WriteLine("Term path: " + term.GetPath());
                Console.WriteLine("IsKeyword:" + term.IsKeyword);
                Console.WriteLine("IsRoot:" + term.IsRoot);
                Console.WriteLine("IsAvailableForTagging:" + term.IsAvailableForTagging);
            catch (TermStoreOperationException exp)

        private static void PrintTermCollection(TermCollection terms)
            if (terms == null)
                throw new System.ArgumentNullException("terms");
            Console.WriteLine("Print terms in the term collection ...");
            foreach (Term term in terms)
                Console.WriteLine(term.Name + ":" + term.Id);


A Term is stored as a TermSetItem object in the TermStore object. It containsreferences to the parts that define a term set item.

A Term can be reused under different parents. It may have custom properties associated with it. It may have multiple Label objects associated with it for ifferent LCID.

When the IsKeyword property is set to true, the Term represents a Keyword. A Keyword does not have any children and is stored in Keyword TermSet.

Initalize a new instance of this class by using the Microsoft.SharePoint.Taxonomy.TermSetItem.CreateTerm method, the static Microsoft.SharePoint.Taxonomy.TermStore.GetTerm method, or by getting it from a TermCollection object.



Gets the DateTime at which this item was created.

(Inherited from TaxonomyItem)

Gets the collection of custom property objects for the current Term object from the read-only dictionary.


Gets or sets the custom sort order of the current Term object.


Gets the Id of the current T:Microsoft.SharePoint.Taxonomy.TaxonomyItem.

(Inherited from TaxonomyItem)

Gets or sets the flag indicating whether a Term object can be used to tag in the tagging UI, but does not affect its visibility.


Gets whether the current Term object has been deprecated.


Gets a Boolean value that indicates whether this term is a hash tag term.


Gets whether the current Term object is a keyword in the Microsoft.SharePoint.Taxonomy.TaxonomySession.KeywordTermSet object.


Gets a Boolean value that indicates if this is a pinned object.


Gets a Boolean value that indicates if this is a pinned object and the root of the pinned tree.


Gets whether the current Term object is a reused Term.


Gets whether the current Term object is at the root of the TermSet object


Gets whether the current Term is the source Term among reused terms


Gets a collection of Label objects for the current Term object.


Gets the DateTime at which this item was most recently updated.

(Inherited from TaxonomyItem)

Gets the collection of local custom properties for this term.


Gets a read-only collection of Term Ids. Term objects identified by those Ids have been merged into the current Term.


Gets or sets the name of the current Term object.


Gets or sets the user who is responsible for the current Term object.


Gets the parent Term object of the current Term.


Gets the TermSet object that contains the term to which this object is pinned.


Gets all of the instances of the current Term object that are reused in other TermSet objects.


Gets the source Term if the current Term is a reused term.


Gets a collection of all immediate child Term objects of the currrent Term object.


Gets the number of child Term objects.


Gets the TermSet object for the current Term object.


Gets the collection of all TermSet objects where the current Microsoft.SharePoint.Term object is located.


Gets the TermStore object from which the current Microsoft.SharePoint.TaxonomyItem was retrieved.

(Inherited from TaxonomyItem)


AddAssociation(Guid, String)

Associates a term with the current hash tag and saves the name of the user who makes the association.


Creates and returns a sibling copy of the current Term object within the current TermSet object.

CreateLabel(String, Int32, Boolean)

Creates a new Label for this Term.

CreateTerm(String, Int32)

Creates a new Term below this TaxonomyItem instance.The name is the default Label for the LCID specified.

(Inherited from TermSetItem)
CreateTerm(String, Int32, Guid)

Creates a new Term object below this Microsoft.SharePoint.TaxonomyItem object.The name is the default Label for the specified LCID.

(Inherited from TermSetItem)

Deletes this Term object and its descendents from the TermStore object.


Deletes all shared custom properties.


Deletes all local custom properties.


Deletes a shared custom property from the current Microsoft.SharePoiint.Taxonomy.Term object.


Deletes a local custom property from the current object.


Deprecates or enables the current Term object.


Verifies whether the current user has the permissions specified.

(Inherited from TermSetItem)

Gets all of the Label objects for the provided lcid parameter.


Gets the default Label for this Term based on LCID.


Gets the description of the Microsoft.SharePoint.Taxoomy.Term object in the language (WorkingLanguage) of the current TermStore object.


Gets the description of the Term in the LCID.


Indicates whether the current Term object is a descendent Term of the specified Term.


Gets the path for this Term object in the default language of the Microsoft.SharePoint.TermStore object.


Gets the path for the current Term in the specified lcid.


Gets a paged collection containing the child Term objects of this Microsoft.SharePoint.TermSetItem object

(Inherited from TermSetItem)
GetTerms(String, Int32, Boolean, StringMatchOption, Int32, Boolean)

Returns all Term instances that are descendants of the current Term with a label in the provided lcid matching the string provided. It only checks default Labels if defaultLabelOnly is provided to be true.


Merge the current Term object with the specified Term and return the combined Term.


Moves the current T:Microsoft.SharePoint.Taxonomy.Term object to be a child of a different Term.


Moves the current Microsoft.SharePoint.Term object to the root of the specified TermSet object


Reassigns the source term status to one of the other reused instances of this Term object.

ReuseTerm(Term, Boolean)

Creates a new reused Term object below this TaxonomyItem object based on a sourceTerm.

(Inherited from TermSetItem)

Creates a new Term below a TaxonomyItem instance based on a sourceTerm and makes the Term pinned so that only the local custom properties, IsAvailableForTagging, and custom sort order for the TermSet can be changed in the TermSet object.

(Inherited from TermSetItem)
SetCustomProperty(String, String)

Adds a new custom property or updates the value of an existing property

SetDescription(String, Int32)

Sets the LCID-specific description of this Term object.

SetLocalCustomProperty(String, String)

Sets a new local custom property or updates the value of an existing local property.

Applies to