TaxonomyFieldValue - Classe

Représente une valeur unique dans un objet TaxonomyField .

Hiérarchie d’héritage

System.Object
  Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue

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

Syntaxe

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

Exemples

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

namespace Microsoft.SDK.SharePointServer.Samples
{
    // This code requires a reference to the Microsoft.SharePoint.dll and Microsoft.SharePoint.Taxonomy.dll
    internal partial class TestTaxonomy
    {
        /// <summary>
        /// This method creates a taxonomy field value for the given taxonomy field with a value of the given term
        /// </summary>
        /// <param name="term">Value to set</param>
        /// <param name="taxonomyField">Field that value is for</param>
        private void TestTaxonomyFieldValueBasic(Term term, TaxonomyField taxonomyField)
        {
            if (term == null)
            {
                throw new ArgumentException("Parameter term cannot be null");
            }
            if (taxonomyField == null)
            {
                throw new ArgumentException("Parameter taxonomyField cannot be null");
            }

            // If you have a term use the following:
            TaxonomyFieldValue taxonomyValue = new TaxonomyFieldValue(taxonomyField);
            taxonomyValue.TermGuid = term.Id.ToString();
            taxonomyValue.Label = term.Name;

            Console.WriteLine("TaxonomyFieldValue created with value " + taxonomyValue.ToString());
        }


        /// <summary>
        /// This method shows how a TaxonomyFieldValue can be created from the results of a TaxonomyWebTaggingControl
        /// </summary>
        /// <param name="text">Text from taxonomy web tagging control which will provide a value</param>
        /// <param name="taxonomyField">Field that value is for</param>
        private void TestTaxonomyFieldValueBasicFromWebControl(string text, TaxonomyField taxonomyField)
        {
            if (taxonomyField == null)
            {
                throw new ArgumentException("Parameter taxonomyField cannot be null");
            }
                       
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentException("a value must be picked from the web tagging control");
            }

            TaxonomyFieldValue taxonomyValue = new TaxonomyFieldValue(taxonomyField);
            taxonomyValue.PopulateFromLabelGuidPair(text);

            Console.WriteLine("TaxonomyFieldValue created with value " + taxonomyValue.ToString());
        }

        /// <summary>
        /// This method shows how to create TaxonomyFieldValue that is not bound to a field
        /// </summary>
        /// <param name="term">Value to set</param>
        private void TestTaxonomyFieldValueNoField(Term term)
        {
            if (term == null)
            {
                throw new ArgumentException("Parameter term cannot be null");
            }

            // When this constructor is used calling ValidatedString will throw an exception
            TaxonomyFieldValue taxonomyValue = new TaxonomyFieldValue("-1" + // We don't know the WssId so default to -1
                ";#" + // This is the lookup field delimiter
                term.Name +  // the label you want the TaxonomyFieldValue to have
                TaxonomyField.TaxonomyGuidLabelDelimiter + // This is the delimiter between the Label and Guid
                term.Id.ToString()); // This is the ID you want the TaxonomyFieldValue to have

            Console.WriteLine("TaxonomyFieldValue created with value " + taxonomyValue.ToString());
        }
    }
}

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

TaxonomyFieldValue - Membres

Microsoft.SharePoint.Taxonomy - Espace de noms

TaxonomyField

Microsoft.SharePoint.Taxonomy

SPFieldLookupValue

Microsoft.SharePoint