TaxonomyFieldControl class
Provides the edit experience for a TaxonomyField object.
Inheritance hierarchy
System.Object
System.Web.UI.Control
Microsoft.SharePoint.WebControls.SPControl
Microsoft.SharePoint.WebControls.TemplateBasedControl
Microsoft.SharePoint.WebControls.FormComponent
Microsoft.SharePoint.WebControls.FieldMetadata
Microsoft.SharePoint.WebControls.BaseFieldControl
Microsoft.SharePoint.Taxonomy.TaxonomyFieldControl
Namespace: Microsoft.SharePoint.Taxonomy
Assembly: Microsoft.SharePoint.Taxonomy (in Microsoft.SharePoint.Taxonomy.dll)
Syntax
'Declaration
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
<AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level := AspNetHostingPermissionLevel.Minimal)> _
Public NotInheritable Class TaxonomyFieldControl _
Inherits BaseFieldControl
'Usage
Dim instance As TaxonomyFieldControl
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
public sealed class TaxonomyFieldControl : BaseFieldControl
Remarks
The taxonomy field control contains a taxonomy Web tagging control. It is reponsiblefor initializing a new instance of the Web tagging control with all of the properties for the TaxonomyField object. It also initializes the taxonomy Web tagging control with its initial value, and then updates the TaxonomyField object with the selected value after edit.
Examples
using System;
using System.IO;
using System.Globalization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
// To build this file, create a Console project and add the following .NET assembly references:
// Microsoft.SharePoint
// Microsoft.SharePoint.Taxonomy
namespace Microsoft.SDK.SharePoint.Taxonomy.Samples
{
public class TestTaxonomyFieldControl
{
private void TestGetTaxonomyCollection()
{
// These test strings contain label-path pairs:
// input1 contains a single label-path pair (a path is a sequence of 1 or more GUIDs)
// input2 contains two label-path pairs
string input1 = "label1|B5EE7261-FD7C-47D2-9DB9-D499640EED01|BA3EBBB7-9C3E-414C-9625-8BCE5F422818";
string input2 = "label2|E87A3A52-365A-4E6B-8F37-F6DCED9F8EDD;label3|1CCB014A-5647-493F-B366-6D9F99FD7894";
Console.WriteLine("input1 = {0}", input1);
Console.WriteLine("input2 = {0}", input2);
// Parse the test string for a single taxonomy field value
TaxonomyFieldValue taxValue1 = TaxonomyFieldControl.GetTaxonomyValue(input1);
// Prints:
// label1 - BA3EBBB7-9C3E-414C-9625-8BCE5F422818
Console.WriteLine("\nGetTaxonomyValue(input1):");
Console.WriteLine("{0} - {1}", taxValue1.Label, taxValue1.TermGuid);
// Parse the test string for a taxonomy field value collection
TaxonomyFieldValueCollection taxFieldValueCollection1 = TaxonomyFieldControl.GetTaxonomyCollection(input1);
TaxonomyFieldValueCollection taxFieldValueCollection2 = TaxonomyFieldControl.GetTaxonomyCollection(input2);
// Prints:
// label1 - BA3EBBB7-9C3E-414C-9625-8BCE5F422818
Console.WriteLine("\nGetTaxonomyCollection(input1):");
foreach (TaxonomyFieldValue fv in taxFieldValueCollection1)
{
Console.WriteLine("{0} - {1}", fv.Label, fv.TermGuid);
}
// Prints:
// label2 - E87A3A52-365A-4E6B-8F37-F6DCED9F8EDD
// label3 - 1CCB014A-5647-493F-B366-6D9F99FD7894
Console.WriteLine("\nGetTaxonomyCollection(input2):");
foreach (TaxonomyFieldValue fv in taxFieldValueCollection2)
{
Console.WriteLine("{0} - {1}", fv.Label, fv.TermGuid);
}
// Convert the field value collections back into a string representation
string output1 = TaxonomyFieldControl.GetMultipleValueText(taxFieldValueCollection1);
string output2 = TaxonomyFieldControl.GetMultipleValueText(taxFieldValueCollection2);
// Prints:
// label1|BA3EBBB7-9C3E-414C-9625-8BCE5F422818
// label2|E87A3A52-365A-4E6B-8F37-F6DCED9F8EDD;label3|1CCB014A-5647-493F-B366-6D9F99FD7894
Console.WriteLine("\nString representations:");
Console.WriteLine(output1);
Console.WriteLine(output2);
}
}
}
using System;
using System.IO;
using System.Globalization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Taxonomy;
// To build this file, add the following .NET assembly references to the project:
// System.Web
// Microsoft.SharePoint
// Microsoft.SharePoint.Taxonomy
namespace Microsoft.SDK.SharePoint.Taxonomy.Samples
{
public class TestTaxonomyFieldControlOnPage : System.Web.UI.Page
{
// Use the following declaration to place the TaxonomyFieldControl on a custom layouts ASPX page:
// <Taxonomy:TaxonomyFieldControl id="myTaxonomyFieldControl" ControlMode="display" runat="server" />
protected TaxonomyFieldControl myTaxonomyFieldControl;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!IsPostBack)
{
// Assume we have a List with a taxonomy field called "Categories"
// Add List=GUID to the URL parameters of the custom aspx page used to view this list,
// where GUID is the ID of the list.
// Binds the TaxonomyFieldControl to the specified field
myTaxonomyFieldControl.FieldName = "Categories";
// A custom target template must be specified for the EmptyValueDescriptionForTargetTemplate property to have any effect
TaxonomyField taxField = myTaxonomyFieldControl.Field as TaxonomyField;
taxField.TargetTemplate = "_layouts/TestTaxonomyFieldControl.aspx";
// Sets the default text to be rendered if the taxonomy field has an empty value and TargetTemplate is specified.
// This property only takes effect if the ControlMode="display".
myTaxonomyFieldControl.EmptyValueDescriptionForTargetTemplate = "No categories have been defined.";
}
}
}
}
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.