I'm having trouble getting the values of a Managed Metadata Field in a SharePoint List.

Basically, what I want to do is given a string (ex. "Category"), it will find all the list items that match that string. The field I am using is Managed Metadata.

What I'm currently doing is getting all List Items then doing the standard:

TaxonomyFieldValueCollection test = item["TaxonomyFieldName"] as TaxonomyFieldValueCollection;

However, I always get "value does not fall within the expected range" error.

Can anyone point out how to do it properly?

Thank you!

  • Can you please check how you are searching inside the taxonomy field values ? We use taxonomyfieldvalueCollection only in places where the field supports multiple values else you can use the taxonomyfieldValue. – Arvi Apr 7 '15 at 9:04
  • My understanding is...Search for value "Category" in the SharePoint list which is a managed metadata field ... – Arvi Apr 7 '15 at 9:06

Option 1: Since you are getting all the items in the list then the caml query would not be of any use now.

TaxonomyFieldValueCollection test = item["TaxonomyFieldName"] asTaxonomyFieldValueCollection;

Now loop in the test collection variable to get all the taxonomy values present in the field.

foreach (var taxonomyValue in test) { if(taxonomyValue.Label
=="Category") { //Item Found } }

By this way you can check the value you are looking for.

Option 2: The other option would be using Caml Query. To form a query on a managed metadata value. Check the below link Query on MM field

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.