Let’s say you have a Managed Metadata column in a SharePoint list, and you want to get the value for that column from an item in the list. Easy right?
(item["MyMetadataColumnName"] as TaxonomyFieldValue).Label
One problem though. It doesn’t matter what the current Culture is, you’ll always get back the default label. If you want to get the localized label, you need to do a whole lot more:
- Create a TaxonomySession
- Get the Term Store for the site collection
- Get the term from the guid of the TaxonomyFieldValue
- And finally… Get the label from the term for the specified culture
Here’s the code:
TaxonomyFieldValue value =item["MyMetadataColumnName"] as TaxonomyFieldValue; TaxonomySession session = new TaxonomySession(SPContext.Current.Site); String localizedValue = session.DefaultSiteCollectionTermStore.GetTerm(new Guid(value.TermGuid)).GetDefaultLabel(CultureInfo.CurrentUICulture.LCID);
Leave a Reply