0

I want to read value from taxonomy field

when I debug I get the below values

item["Department"]
Count = 4
    [0]: {[_ObjectType_, SP.Taxonomy.TaxonomyFieldValue]}
    [1]: {[Label, Some Department]}
    [2]: {[TermGuid, 345667-345-44230a-6574-453543]}
    [3]: {[WssId, 44]}

Now, I want to get that "Some Department" value from it. I tried accessing the label item["Department"][1] but it didnt work

I am not able to use

new System.Collections.Generic.Mscorlib_DictionaryDebugView<string, object>(item["Department"]).Items[1].Value; 

as it says

Mscorlib_DictionaryDebugView' is inaccessible due to its protection level Package

How should i do it?

1

Try the below code:

ClientContext clientContext = new ClientContext("http://c4968397007/");

// SharePoint web
Web web = clientContext.Web;

// Get the list using Title
List list = web.Lists.GetByTitle("Custom");

// Get the list item by id
ListItem item = list.GetItemById(2);
clientContext.Load(item);

// Execute the query to the server
clientContext.ExecuteQuery();


//get single taxonomy field value
TaxonomyFieldValue termValue = item["Department"] as TaxonomyFieldValue;

Console.WriteLine(termValue.Label);
  • its of type {Microsoft.SharePoint.Client.Taxonomy.TaxonomyFieldValue} – Vignesh Subramanian Nov 22 '16 at 8:41
  • yes check this. Have updated code. //get single taxonomy field value TaxonomyFieldValue termValue = item["Department"] as TaxonomyFieldValue; Console.WriteLine(termValue.Label); – Gautam Sheth Nov 22 '16 at 8:44
  • taxFieldValueColl is coming as null – Vignesh Subramanian Nov 22 '16 at 9:16
  • check now , have removed the taxfieldvaluecoll – Gautam Sheth Nov 22 '16 at 9:17
0

I used the below code

                        try
                        {
                            newItem["Department"] = ((Microsoft.SharePoint.Client.Taxonomy.TaxonomyFieldValue)(item["PokagonDepartment"])).Label;
                        }
                        catch (Exception ex)
                        {
                          // some things to do on exception
                        }

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.