8

I am trying to retrieve the Children Keywords of another Keyword from its URI with the following code:

if (kwdOrCatURI.StartsWith("tcm:"))
 {
     if (kwdOrCatURI.EndsWith("-1024"))
     {
         rootkeyword = factory.GetTaxonomyKeyword(kwdOrCatURI);
         taxonomychildren = GetKeywords(rootkeyword);
     }
 }

....

private static ArrayList GetKeywords(Keyword kwd)
{
    ArrayList arraylist = new ArrayList();
    if (kwd != null)
    {
        foreach (Keyword childkeyword in (IEnumerable)kwd.KeywordChildren)
        {
            arraylist.Add(childkeyword);
        }
    }
    return arraylist;
}

Unfortunately, I am not able to get the children, since the list is always empty. However if I "iterate" & "browse" over the category I am able to get to all its children...

Anyone has an example on how to retrieve the children of a Keyword from its URI without having to iterate over the entire category?

Thanks!

7

Ok, It seems it's been a while since I wrote code... it is quite simple, here the solution:

  1. Get The keyword
  2. From the Keyword, get its TaxonomyURI
  3. Now using the API, get the keyword with its children:

    rootkeyword = factory.GetTaxonomyKeyword(kwdOrCatURI);
    //rootkeyword.TaxonomyUri
    rootkeyword = factory.GetTaxonomyKeywords(rootkeyword.TaxonomyUri, 
                                     new CompositeFilter(), kwdOrCatURI, new Keyword[]{});
    taxonomychildren = GetKeywords(rootkeyword);
    

Thank you Asier.

  • It is always a pleasure to help :) – Asier Fernández May 6 '13 at 11:46
  • Jamie, You should go ahead and mark your answer as the accepted answer for your question. – Glenn Stevens May 9 '13 at 6:19
2

Here's a snippet I have as my own example:

To get your keyword

using Tridion.ContentDelivery.Taxonomies;

TaxonomyFactory taxonomyFactory = new TaxonomyFactory();
Keyword keyWord = taxonomyFactory.GetTaxonomyKeywords("yourcategorytcmid");

Now you have your keyword

You've access to:

keyWord.KeywordChildren

If you're going to loop this list it's best to check the object is of type

Tridion.ContentDelivery.Taxonomies.Keyword

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.