Copied to clipboard

Flag this post as spam?

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


  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Oct 12, 2009 @ 13:28
    Sebastiaan Janssen
    0

    How do I loop through parent nodes

    I need to go through some CMSNodes and I'm trying to find the grandparent, under which an X number of nodes are present.

    So I thought I would do something like node.Parent.Parent.. but I don't know how many parents there are...

    I'm sure the answer is incredibly obvious, but I am completely blanking out here. 

  • Dirk De Grave 4537 posts 6006 karma points MVP 3x admin c-trib
    Oct 12, 2009 @ 15:18
    Dirk De Grave
    0

    Sebastiaan,

    You could use the Path property which specifies complete path for any given node. Or, use the Parent property and check for null (altho not sure if last method is useful)

     

    Cheers,

    /Dirk

     

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Oct 12, 2009 @ 15:28
    Thomas Höhler
    0

    Implement a recursive function for that. Do you need an example?

    Thomas

  • Sebastiaan Janssen 4899 posts 14655 karma points MVP admin hq
    Oct 12, 2009 @ 16:00
    Sebastiaan Janssen
    0

    Thanks guys, I was just having a brainfart, I implemented it this way:

                        CMSNode grandParent = new CMSNode(parentNode.Id);
                        while (grandParent.Level > 1)
                        {
                            grandParent = grandParent.Parent;
                        }
    

  • Thomas Höhler 1237 posts 1709 karma points MVP
    Oct 12, 2009 @ 17:00
    Thomas Höhler
    0

    You can also use the Path value for that:

    CMSNode grandParent = new CMSNode(int.Parse(parentNode.Path.Split(",".ToCharArray())[1]));

    which takes the nodeId from the level 1 node of the actual node...

    hth, Thomas

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies