TaxonomySession TaxonomySession TaxonomySession Class

Definition

Wraps all of the associated TermStore objects for an SPSite object.

public ref class TaxonomySession sealed
[Microsoft.SharePoint.Client.ClientCallableType(ClientLibraryTargets=Microsoft.SharePoint.Client.ClientLibraryTargets.NonRESTful, FactoryType=typeof(Microsoft.SharePoint.Taxonomy.Internal.TaxonomyClientObjectFactory), ObjectIdentityPropertyName="CanonicalId", ServerTypeId="981CBC68-9EDC-4f8d-872F-71146FCBB84F")]
public sealed class TaxonomySession
Public NotInheritable Class TaxonomySession
Inheritance
TaxonomySessionTaxonomySessionTaxonomySession
Attributes
Microsoft.SharePoint.Client.ClientCallableTypeAttribute

Examples

<pre><code>using System;

using System.IO; using System.Globalization; using System.Collections.Specialized; using Microsoft.SharePoint; using Microsoft.SharePoint.Taxonomy;

namespace Microsoft.SDK.SharePointServer.Samples { public static class TaxonomySamples { public static void UseSession(SPSite site) { TaxonomySession session = new TaxonomySession(site);

        // Get the default keyword TermStore for the provided site
        TermStore defaultKeywordStore = session.DefaultKeywordsTermStore;
        if (defaultKeywordStore != null)
        {
            Console.WriteLine(defaultKeywordStore.Name);
        }
        else
        {
            Console.WriteLine("Default keyword store is not configured or not configured properly");
        }

        // Get the default site collection TermStore associated with the provide site.
        TermStore defaultSiteCollectionStore = session.DefaultSiteCollectionTermStore;
        if (defaultSiteCollectionStore != null)
        {
            Console.WriteLine(defaultSiteCollectionStore.Name);
        }
        else
        {
            Console.WriteLine("Default site collection TermStore is not configured or not configured properly");
        }

        // Get all the TermStores associated with the provided site.
        TermStoreCollection termStores = session.TermStores;
        Console.WriteLine(termStores.Count);

        // Get all the offline TermStore names
        StringCollection names = session.OfflineTermStoreNames;
        Console.WriteLine(names.Count);

        // Resync the taxonomy hidden list to make sure it is update-to-date
        TaxonomySession.SyncHiddenList(site);
    }

    public static void RetrieveTerm(SPSite site, Guid termId)
    {
        TaxonomySession session = new TaxonomySession(site);

        // Retrieves a Term with the provided Id
        Term term = session.GetTerm(termId);
        Console.WriteLine("Got Term " + term.Name);
    }

    public static void SearchTermsByLabel(SPSite site, string prefix)
    {
        TaxonomySession session = new TaxonomySession(site);

        // Search all Terms that start with the provide prefix from
        // all TermStores associated with the provided site.
        TermCollection terms = session.GetTerms(prefix,
            true, // Only search in default labels
            StringMatchOption.StartsWith,
            5,  // The maximum number of terms returned from each TermStore
            true); // The results should not contain unavailable terms

        Console.WriteLine("The number of matching Terms is " + terms.Count);
    }


    public static void SearchTermsByCustomProperty(SPSite site, 
        string customPropertyName)
    {
        TaxonomySession session = new TaxonomySession(site);

        // Search all Terms that contain a custom property with the provided name
        // from all TermStores associated with the provided site.
        TermCollection terms = session.GetTermsWithCustomProperty(
            customPropertyName,
            true); // The results should not contain unavailable Terms

        Console.WriteLine("The number of matching Terms is " + terms.Count);
    }

    public static void SearchTermSetsByName(SPSite site,
        string termSetName)
    {
        TaxonomySession session = new TaxonomySession(site);

        // Search all TermSets that are using the provided name in current
        // UI LCID from all TermStores associated with the provided site.
        TermSetCollection termSets = session.GetTermSets(termSetName,
            CultureInfo.CurrentUICulture.LCID);

        Console.WriteLine("The number of matching Term Sets is " + termSets.Count);
    }

    public static void SearchTermSetsByTermLabels(SPSite site,
        string[] termLabels)
    {
        TaxonomySession session = new TaxonomySession(site);

        // Returns all TermSet instances from all TermStores that contain terms 
        // with matching labels for all specified strings.
        TermSetCollection termSets = session.GetTermSets(termLabels);
        Console.WriteLine("The number of matching Term Sets is " + termSets.Count);
    }

}

}

Remarks

The TaxonomySession object is the starting point for all operations involving objects from the taxonomy. It provides access to one or more TermStore objects, (for example, managed metadata connections), where the Group, TermSet, and Term objects reside.

Constructors

TaxonomySession(SPSite) TaxonomySession(SPSite) TaxonomySession(SPSite)

Initializes a new instance of a TaxonomySession object that is scoped to a specific SPSite object.

TaxonomySession(SPList, Boolean) TaxonomySession(SPList, Boolean) TaxonomySession(SPList, Boolean)

Creates a new session for performing taxonomy operations, using the specified SPList as the context for security permissions.

TaxonomySession(SPSite, Boolean) TaxonomySession(SPSite, Boolean) TaxonomySession(SPSite, Boolean)

Initializes a new instance of a TaxonomySession object that is scoped to a specific SPSite object.

TaxonomySession(SPWeb, Boolean) TaxonomySession(SPWeb, Boolean) TaxonomySession(SPWeb, Boolean)

Creates a new session for performing taxonomy operations, using the specified SPWeb as the context for security permissions.

Properties

DefaultKeywordsTermStore DefaultKeywordsTermStore DefaultKeywordsTermStore

Gets the TermStore object to be used for keywords

DefaultSiteCollectionTermStore DefaultSiteCollectionTermStore DefaultSiteCollectionTermStore

Gets the TermStore object to be used for metadata that are specific to the site collection, such as column-specific TermSet objects.

OfflineTermStoreNames OfflineTermStoreNames OfflineTermStoreNames

Gets a StringCollection of names of TermStore objects that are currently offline.

TermStores TermStores TermStores

A collection of TermStore objects that are associated with the SPWebApplication object of the current SPSite object.

Methods

GetTerm(Guid) GetTerm(Guid) GetTerm(Guid)

Gets a Term object that is based on Term IDs. If the current Term belongs to multiple TermSet objects, it will arbitrarily return the Term from one of the TermSet objects.

GetTerms(Guid[]) GetTerms(Guid[]) GetTerms(Guid[])

Gets a set of Term objects based on Term IDs. If a Term is part of more than one TermSet object, it will arbitrarily return the Term object from one of the TermSet objects.

GetTerms(String, Boolean) GetTerms(String, Boolean) GetTerms(String, Boolean)

Gets from all TermStore objects with a Label object that matches the provided string, the Term objects from all TermSet objects that are not scoped to an SPSite object.

GetTerms(String, Int32, Boolean) GetTerms(String, Int32, Boolean) GetTerms(String, Int32, Boolean)

Gets Term objects from all of the TermSet objects, which are not scoped to an SPSite object, from all TermStore objects with a Label object in the provided lcid matching the string provided.

GetTerms(String, Boolean, StringMatchOption, Int32, Boolean) GetTerms(String, Boolean, StringMatchOption, Int32, Boolean) GetTerms(String, Boolean, StringMatchOption, Int32, Boolean)

Searches Label objects in all working languages, and returns Term objects from all TermSet objects, which are not scoped to an SPSite object, from all TermStore objects with a Label object matching the provided string.

GetTerms(String, Int32, Boolean, StringMatchOption, Int32, Boolean, Boolean) GetTerms(String, Int32, Boolean, StringMatchOption, Int32, Boolean, Boolean) GetTerms(String, Int32, Boolean, StringMatchOption, Int32, Boolean, Boolean)

Searches labels in the provided lcid, and returns Term objects from all TermSet objects, which are not scoped to an SPSite object, from all TermStore objects with a Label matching the provided string.

GetTermSets(String[], Int32) GetTermSets(String[], Int32) GetTermSets(String[], Int32)

Gets all of the TermSet objects from all of the TermStore objects that contain Term objects with matching LCID specific labels for all specified strings.

GetTermSets(String[]) GetTermSets(String[]) GetTermSets(String[])

Gets all TermSet objects from all TermStore objects that contain Term objects with matching Label objects for all specified strings.

GetTermSets(String, Int32) GetTermSets(String, Int32) GetTermSets(String, Int32)

Gets all TermSet objects from all TermStore objects that have a name in the specified language.

GetTermsInDefaultLanguage(String, Boolean, StringMatchOption, Int32, Boolean, Boolean) GetTermsInDefaultLanguage(String, Boolean, StringMatchOption, Int32, Boolean, Boolean) GetTermsInDefaultLanguage(String, Boolean, StringMatchOption, Int32, Boolean, Boolean)

Searches Label objects in the TermStore objects’ default language, and returns Term objects that are not scoped to an SPSite object from all TermSet objects, in all TermStore objects that contain a Label object that matches the provided string.

GetTermsInWorkingLocale(String, Boolean, StringMatchOption, Int32, Boolean, Boolean) GetTermsInWorkingLocale(String, Boolean, StringMatchOption, Int32, Boolean, Boolean) GetTermsInWorkingLocale(String, Boolean, StringMatchOption, Int32, Boolean, Boolean)

Searches Label objects in the TermStore working language, and returns Term objects from all TermSet objects, which are not scoped to an SPSite object, from all TermStore objects with a Label matching the provided string.

GetTermsWithCustomProperty(String, Boolean) GetTermsWithCustomProperty(String, Boolean) GetTermsWithCustomProperty(String, Boolean)

Gets Term objects from all TermStore objects that have a property with the provided property name.

GetTermsWithCustomProperty(String, Int32, Boolean) GetTermsWithCustomProperty(String, Int32, Boolean) GetTermsWithCustomProperty(String, Int32, Boolean)

Gets Term objects from all TermStore objects that have a property with the provided property name.

GetTermsWithCustomProperty(String, String, Boolean) GetTermsWithCustomProperty(String, String, Boolean) GetTermsWithCustomProperty(String, String, Boolean)

Gets Term objects from all TermStore objects that have a property with the provided property name and the provided property value.

GetTermsWithCustomProperty(String, String, StringMatchOption, Boolean) GetTermsWithCustomProperty(String, String, StringMatchOption, Boolean) GetTermsWithCustomProperty(String, String, StringMatchOption, Boolean)

Gets Term objects from all TermStore objects that have a property with the provided property name and the property value matching the provided value in the specified way.

GetTermsWithCustomProperty(String, String, StringMatchOption, Int32, Boolean) GetTermsWithCustomProperty(String, String, StringMatchOption, Int32, Boolean) GetTermsWithCustomProperty(String, String, StringMatchOption, Int32, Boolean)

Gets Term objects from all TermStore objects that have a property with the provided property name and the property value matching the provided value in the specified way.

SyncHiddenList(SPSite) SyncHiddenList(SPSite) SyncHiddenList(SPSite)

Syndicates the taxonomy hidden list on the provided SPSite object.

UpdateCache() UpdateCache() UpdateCache()

Forces the taxonomy cache to communicate with the Managed Metadata Service to check for changes to any taxonomy objects.

Extension Methods

ToJson(Object) ToJson(Object) ToJson(Object)

Applies to