4

I am using the below code to fetch metadata from Keywords using Taxonomy API. I am able to retrieve the Keyword names, but not their metadata. Please suggest.

TaxonomyFactory taxonomyFactory = new TaxonomyFactory(); 
PublicationCriteria pubCr = new PublicationCriteria(41); 
ItemTypeCriteria isKwd = new ItemTypeCriteria(1024); 
Criteria[] arrCriteria = {pubCr,isKwd}; 
Criteria c = new AndCriteria(arrCriteria); 
Query q = new Query(c); 
foreach (string uri in q.ExecuteQuery())
{ 
Response.Write("
+ test - " + taxonomyFactory.GetTaxonomyKeyword(uri).KeywordName + "
"); 
Keyword item = taxonomyFactory.GetTaxonomyKeyword(uri);
CustomMeta customMeta = item.KeywordMeta; 
if (customMeta != null) 
{ 
IDictionary mnd = customMeta.NameValues; 
IEnumerator mne = mnd.GetEnumerator(); 
if (mne != null) 
{ 
while(mne.MoveNext()) 
{ 
DictionaryEntry de = (DictionaryEntry)mne.Current; 
NameValuePair currentMeta = (NameValuePair)de.Value; 
if (currentMeta != null) 
{ 
Response.Write(currentMeta.Value); // this is actually returning the TCM ID's and not the values
} 
} 
} 
} 
} 
2

Are the keyword meta values component links? If so - you'll need to get those components separately and make sure you publish the components out somewhere. The only thing that is stored in KeywordMeta is a tcm uri in the form of tcm:0-<id>.

The same is true for linked Binaries.

| improve this answer | |
  • They are not comp links. Actually I have a metadata schema which displays list of keywords from another Category. Doing currentMeta.Value in the above code returns the tcm id which I am able to manipulate to match the tcm id of the keyword(by replacing '0' with the pub id). Then i m using the tf.GetTaxanomyKeyword(correcturi).KeywordName to retrieve the required title of the keyword. But it's returning object reference not set error. I have published the taxonomy. – Manish May 7 '13 at 12:21
  • I think you're doing correct in essence. Try to debug the call for fetching the keyword set in metadata to see what's null. Otherwise, try to readd the filter or use a separate TaxonomyFactory. – Raimond May 24 '13 at 12:30

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.