NavigationTerm class

NavigationTerm class

SharePoint 2013

Specifies navigation behavior and properties for a Term object that is used to drive the navigation and friendly URLs for a website.


Namespace:  Microsoft.SharePoint.Publishing.Navigation
Assembly:  Microsoft.SharePoint.Publishing (in Microsoft.SharePoint.Publishing.dll)

[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public abstract class NavigationTerm : NavigationTermSetItem

This class is analogous to the Term class in the Microsoft.SharePoint.Taxonomy namespace.

The NavigationTerm class adds properties and operations that are specific to managed navigation. The additional state is stored in the CustomPropeties() property and should only be accessed via classes in the Microsoft.SharePoint.Publishing.Navigation namespace. A NavigationTerm object belongs to a NavigationTermSet object.

The NavigationTerm and NavigationTermSet objects have two modes: an “editable” mode and a “read-only” mode. NavigationTerm objects are stored in the taxonomy navigation cache, which can be accessed by using functions in the TaxonomyNavigation static class.

The following example demonstrates creating a sample term set and then configuring a SharePoint Server web site to use managed navigation with the 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;

        //Configures the web site to use Taxonomy navigation with the sample term set.
        public static NavigationTermSet SetUpSampleNavTermSet(TaxonomySession taxonomySession, SPWeb web)
            NavigationTermSet termSet = RecreateSampleNavTermSet(taxonomySession, web);

            // Clear out any old settings
            WebNavigationSettings webNavigationSettings = new WebNavigationSettings(web);
            webNavigationSettings.GlobalNavigation.Source = StandardNavigationSource.TaxonomyProvider;
            webNavigationSettings.GlobalNavigation.TermStoreId = termSet.TermStoreId;
            webNavigationSettings.GlobalNavigation.TermSetId = termSet.Id;
            webNavigationSettings.CurrentNavigation.Source = StandardNavigationSource.TaxonomyProvider;
            webNavigationSettings.CurrentNavigation.TermStoreId = termSet.TermStoreId;
            webNavigationSettings.CurrentNavigation.TermSetId = termSet.Id;

            return termSet;

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