TaxonomyFieldValue Class
Represents a single value held in a TaxonomyField object.
Inheritance Hierarchy
System.Object
Microsoft.SharePoint.Taxonomy.TaxonomyFieldValue
Namespace: Microsoft.SharePoint.Taxonomy
Assembly: Microsoft.SharePoint.Taxonomy (in Microsoft.SharePoint.Taxonomy.dll)
Syntax
'Declaration
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
Public Class TaxonomyFieldValue
'Usage
Dim instance As TaxonomyFieldValue
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class TaxonomyFieldValue
Examples
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());
}
}
}
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.