TaxonomySession - Classe

Encapsule tous les objets associés TermStore pour un objet SPSite .

Hiérarchie d’héritage

System.Object
  Microsoft.SharePoint.Taxonomy.TaxonomySession

Espace de noms :  Microsoft.SharePoint.Taxonomy
Assembly :  Microsoft.SharePoint.Taxonomy (dans Microsoft.SharePoint.Taxonomy.dll)

Syntaxe

'Déclaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class TaxonomySession
'Utilisation
Dim instance As TaxonomySession
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class TaxonomySession

Remarques

L'objet TaxonomySession est le point de départ pour toutes les opérations impliquant des objets à partir de la taxonomie. Il fournit l'accès à un ou plusieurs objets banque de termes, (par exemple, les connexions de métadonnées managées), où se trouvent les objets de groupe, TermSet et période.

Exemples

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);
        }

    }
}

Cohérence de thread

Tous les membres statique (Partagé dans Visual Basic)s publics de ce type sont thread-safe. Cela n’est pas garanti pour les membres d’instance.

Voir aussi

Référence

TaxonomySession - Membres

Microsoft.SharePoint.Taxonomy - Espace de noms