I am create Sequential Workflow for document library in Visual Studio 2010 and also create Meta Data Column Field which field name is TexonomyType.

first ways i get TexonomyField like this:

    TaxonomyField tf = (TaxonomyField)workflowProperties.Item["TexonomyType"]; 

tf is null

than try this ways :

        TaxonomyField tf = workflowProperties.Item.Fields.GetFieldByInternalName("TexonomyType") as TaxonomyField;

        TaxonomyFieldValue taxonomyFieldValue = new TaxonomyFieldValue(fieldToSet);

        string value = taxonomyFieldValue.Label;

here i got the TaxonomyField but Label getting always Empty.

How to Get TaxonomyField value for Current listitem?


You can use code which use following classes to get the Taxonomy Field labels..

TaxonomyFieldValueCollection coll = (list.Items[0]["Field Name"] as TaxonomyFieldValueCollection);

StringBuilder sb = new StringBuilder();

        foreach (TaxonomyFieldValue val in coll)
            // get termguid
            string termGuid = val.TermGuid;

            // get label
            string label = val.Label;

            // build the string
            sb.AppendLine(string.Format("GUID: {0}, Label: {1}", termGuid, label));

        lblFieldViewer.Text = sb.ToString();
  • I am using its only Taxonomyfield not TaxonomyMulti type. when i have try this code getting error like : cannt cast from TaxonomyField to TaxonomyFieldValueCollection – Jignesh Rajput May 11 '12 at 16:33
  • hope you are not casting workflowProperties.Item.Fields.GetFieldByInternalName("TexonomyType").. are you? which line is throwing error? – Ashish Patel May 11 '12 at 17:58
  • no its works.but when i go for get TaxonomyFieldValue with for label value always getting Empty. – Jignesh Rajput May 11 '12 at 18:02
  • Technet:Setting and Getting a Metadata field social.technet.microsoft.com/wiki/contents/articles/… – Ryan Jan 14 '15 at 15:05

I found the value by below way:

        TaxonomyField fieldToSet = ListItem.Fields["TexonomyType"] as TaxonomyField;
        string value = string.Empty;
        if (fieldToSet != null)
            object itemObj = ListItem["TexonomyType"];
            value = Convert.ToString(fieldToSet.GetFieldValueAsText(itemObj));

Hops its helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.