Copied to clipboard

Flag this post as spam?

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


  • Dan 1288 posts 3921 karma points c-trib
    Sep 04, 2013 @ 17:28
    Dan
    0

    How to get node by name programmatically in v6.0.2

    Hi,

    I have a parent content node which can be a hard-coded id. I want to find any child node of that parent by node name, programmatically in Umbraco 6.0.2.

    I'm a little confused as to the best way to do this with the recent API updates. I'd rather do things the 'new' way rather than the 'legacy' way if there are such things.

    Should I use the 'Document' object (http://our.umbraco.org/documentation/reference/Management/Documents/) or the 'Content' object (http://our.umbraco.org/documentation/reference/Management-v6/Models/Content) or the node factory or something else?

    Thanks folks.

  • Kevin Jump 2342 posts 14889 karma points MVP 8x c-trib
    Sep 05, 2013 @ 13:00
    Kevin Jump
    0

    if by programmatically you mean in a dll ? not razor then i think you can use the ContentService in 6.0.2 (you definitely can in 6.1.x)

    enumerate all children.

     IContentService _cs = ApplicationContext.Current.Services.ContentService;
    
    
     foreach (IContent child in _cs.GetChildren(nodeId))
     {
       ... child.Name ...
    
     }
    

    by name then replace _cs.GetChildren with _cs.GetChildrenByName(nodeId, name)

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Sep 05, 2013 @ 14:08
    Lee Kelleher
    0

    @Dan - are you wanting to get published content or from the database?

    Am I right in thinking that the new ContentService API deals with content at the database level? (akin to the old Document) - whereas the IPublishedContent is akin to the old NodeFactory.Node?

Please Sign in or register to post replies

Write your reply to:

Draft