Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

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();
share|improve this answer
    
I am using its only Taxonomyfield not TaxonomyMulti type. when i have try this code getting error like : cannt cast from TaxonomyField to TaxonomyFieldValueCollection –  jigs 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. –  jigs May 11 '12 at 18:02
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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