TaxonomyFieldValue TaxonomyFieldValue TaxonomyFieldValue Class

Definition

Represents a single value held in a TaxonomyField object.

public ref class TaxonomyFieldValue
[Microsoft.SharePoint.Client.ClientCallableType(ClientLibraryTargets=Microsoft.SharePoint.Client.ClientLibraryTargets.NonRESTful, ServerTypeId="19E70ED0-4177-456b-8156-015E4D163FF8", ValueObject=true)]
[System.Runtime.Serialization.DataContract]
public class TaxonomyFieldValue
Public Class TaxonomyFieldValue
Inheritance
TaxonomyFieldValueTaxonomyFieldValueTaxonomyFieldValue
Attributes
Microsoft.SharePoint.Client.ClientCallableTypeAttribute DataContractAttribute

Examples

<pre><code>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 { /// &lt;summary&gt; /// This method creates a taxonomy field value for the given taxonomy field with a value of the given term /// &lt;/summary&gt; /// &lt;param name="term"&gt;Value to set&lt;/param&gt; /// &lt;param name="taxonomyField"&gt;Field that value is for&lt;/param&gt; 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());
    }


    /// &amp;lt;summary&amp;gt;
    /// This method shows how a TaxonomyFieldValue can be created from the results of a TaxonomyWebTaggingControl
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="text"&amp;gt;Text from taxonomy web tagging control which will provide a value&amp;lt;/param&amp;gt;
    /// &amp;lt;param name="taxonomyField"&amp;gt;Field that value is for&amp;lt;/param&amp;gt;
    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());
    }

    /// &amp;lt;summary&amp;gt;
    /// This method shows how to create TaxonomyFieldValue that is not bound to a field
    /// &amp;lt;/summary&amp;gt;
    /// &amp;lt;param name="term"&amp;gt;Value to set&amp;lt;/param&amp;gt;
    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());
    }
}

}

Constructors

TaxonomyFieldValue(SPField) TaxonomyFieldValue(SPField) TaxonomyFieldValue(SPField)

Initializes a new instance of a TaxonomyFieldValue object that is bound to the specified Microsoft.SharePointSPField object.

TaxonomyFieldValue(String) TaxonomyFieldValue(String) TaxonomyFieldValue(String)

Initializes a new instance of the TaxonomyFieldValue object that is based on the specified field value.

TaxonomyFieldValue(String, SPField) TaxonomyFieldValue(String, SPField) TaxonomyFieldValue(String, SPField)

Initializes a new instance of the Microsoft.SharePoint.Taxnomy.TaxonomyFieldValue object that is bound to the specified SPField object and is based on the specified field value.

Properties

Label Label Label

Gets or sets the label of the Microsoft.SharePoint.TaxonomyField object.

TermGuid TermGuid TermGuid

Gets or sets a string representing the term GUID.

ValidatedString ValidatedString ValidatedString

Gets a validated, serialized string representation of the TaxonomyFieldValue object.

WssId WssId WssId

Gets or sets the list item ID of the list item containing the taxonomy field value that is encapsulated by the TaxonomyFieldValue object.

Methods

PopulateFromLabelGuidPair(String) PopulateFromLabelGuidPair(String) PopulateFromLabelGuidPair(String)

Updates the value of the TaxonomyFieldValue object with the specified text data.

ToString() ToString() ToString()

Returns a formatted string representing the TaxonomyFieldValue object.

Extension Methods

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

Applies to