Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kurniawan Kurniawan 202 posts 225 karma points
    Feb 02, 2011 @ 02:31
    Kurniawan Kurniawan
    0

    How to get all child nodes with particular type

    Hi all,

     

    Do you know how to get all child nodes with a particular type for example,

    I want to get all news item in particular category.

    I try to do it in umbraco.linq.
    newsCat.NewsItems.ToList();

    but give me this error

    The given key was not present in the dictionary

     

    So I try to find solution in using Umbraco API ?

     

    Is there any good documentation for umbraco API ?

    Thanks

     

     

     

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 02, 2011 @ 08:39
    Jan Skovgaard
    1

    Hi Kurniawan

    Seems like the reference to the API documenatation was lost with the launch of the new umbraco.org website. However in this post http://our.umbraco.org/forum/developers/api-questions/13618-Where-did-the-API-documentation-go you can get af .chm file on 41MB that contains the documentation.

    Hope thils helps.

    /Jan

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 02, 2011 @ 14:32
    Tom Fulton
    1

    Hi,

    I haven't used Linq2Umbraco yet, but I know with the Document API you can do something like this:

    Document doc = new Document(1234);
    foreach (Document d in doc.Children.Where(n => n.ContentType.Alias.ToString() == "YourDocTypeAlias"))
    {
    }

    I don't think there's a similar way to do this using nodeFactory though (short of looping through all children and adding a condition inside the loop to check the NodeTypeAlias)

    You can also find (some) information in the API Cheatsheet section of the wiki.

    -Tom

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 02, 2011 @ 15:48
    Hendy Racher
    1

    Hi,

    FYI, in uComponents there's a helper library called uQuery that adds XPath axis type extension methods to the Node and Media objects, allowing their tree structure to queryable with Linq.

    using System.Linq;
    using umbraco.presentation.nodeFactory;
    using uComponents.Core.uQueryExtensions;

    Node node = new Node(123);

    List<Node> childNodes = node.GetChildNodes().Where(node => node.NodeTypeAlias == "alias");

    HTH,

    Hendy

     

     

  • Kurniawan Kurniawan 202 posts 225 karma points
    Feb 03, 2011 @ 00:06
    Kurniawan Kurniawan
    0

    Thanks Guys,

     

    But Do you know how to get all child inheritly using linq ?

    Actually we can do looping (while loop), but is it possible using linq ?

     

    Thanks

  • andrew shearer 506 posts 653 karma points
    Feb 07, 2011 @ 05:49
    andrew shearer
    1

    Hendy,

    isn't this namespae obsolete?

    using umbraco.presentation.nodeFactory;

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 07, 2011 @ 08:41
    Hendy Racher
    0

    Hi Andrew,

    The umbraco.presentation.nodeFactory namespace is required, as GetChildNodes() is an extension method on the Node object, and the .NodeTypeAlias is a property of Node.

    Cheers,

    Hendy

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 11, 2011 @ 19:49
    Hendy Racher
    0

    Hi Andrew,

    You're totally right, the namespace isn't needed at all provided you don't directly instantiate a Node object - had assumed otherwise.

    Cheers,

    Hendy

Please Sign in or register to post replies

Write your reply to:

Draft