Copied to clipboard

Flag this post as spam?

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


  • Sony 20 posts 40 karma points
    Dec 31, 2010 @ 08:06
    Sony
    0

    find childnode of specific documenttype

    Hello folks.,

    very happy new year to all..

    i need to find childnode of specific documenttype .

    example : i have a node (it is a parentnode).

    it has child nodes and decendant node of child.

    i need to find nodes of specific documentype(here gallery) in all these child and decendant nodes using usercontrol(C#). any siggestions?

    thank you

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jan 02, 2011 @ 14:26
    Sebastiaan Janssen
    0

    In your usercontrol, make sure that you have a reference to the umbraco.dll. 

    Then do something like this: 

    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using umbraco.presentation.nodeFactory;
    
    namespace Your.Namespace
    {
        public class WebUserControl1 : UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                var currentNode = Node.GetCurrent();
                var children = new List<Node>();
                foreach (Node child in currentNode.Children)
                {
                    if (child.NodeTypeAlias == "gallery")
                        children.Add(child);
                }
            }
        }
    }

    Then you can use the children list for whatever you need it.

  • Justin Moore 41 posts 100 karma points
    Feb 03, 2011 @ 03:28
    Justin Moore
    0


    if you were working from a Document rather than a Node you can do something like

    foreach(Document child in currentDoc.Children.Where(x => x.ContentType.Alias == "gallery")

    but I think the above is database intensive so you're better to do this

    Document[] children = doc.Children.Where(x => x.ContentType.Alias == "gallery"); 
    foreach (Document child in children) 
    {...}

    http://our.umbraco.org/wiki/reference/api-cheatsheet/enumerating-documents

    but you're better using nodes instead of documents anyway

Please Sign in or register to post replies

Write your reply to:

Draft