3

In Tridion 2011 I have a componen in which in the metadata fields has a keyword with different values. How should I get the selected value in c#. I tried the next but I get the name of the key not the selected value.

ItemFields fields = new ItemFields(component.Metadata, component.MetadataSchema);
KeywordField key = (KeywordField)fields[fieldName];
return key.Name;

but I get the name of the keyword not the selected value. Keyword: Business Area Values: Corporate. Decorative paints. Performance coatings(selected one)

1 Answer 1

4

The KeywordField is the field itself, not the chosen Keyword. You need to get it's value... something like this:

ItemFields fields = new ItemFields(component.Metadata, component.MetadataSchema);
KeywordField keywordField = (KeywordField)fields[fieldName];
Keyword keyword = (Keyword)keywordField.Value;
return keyword.Title;
1
  • You are right. I did the changes and the code works perfect. Thanks a lot Commented Mar 15, 2016 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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