Copied to clipboard

Flag this post as spam?

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


  • Sean 141 posts 179 karma points
    Apr 13, 2011 @ 14:56
    Sean
    0

    The best way to navigate n levels of nodes using nodeFactory?

    Hi There,

    I have a need to generate the node structure from C#. What's the best way of doing this given that I don't know how many levels there are?

    I'm currently using this approach:

      foreach (umbraco.presentation.nodeFactory.Node n in node.Children)
                        {

    //display

    }

    If anyone has a snippet they could post?

    Thanks in advance

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Apr 13, 2011 @ 15:07
    Dirk De Grave
    0

    Sean,

    you should use a recursive approach then...

     

    public void iterateNodes(Node node) {
      //display node
      if (node.Children.Count > 0) {
        var childNodes = node.Children;
        foreach (Node childNode in childNodes) {
          iterateNodes(childNode);
        }
      }
    }

    (written on top of my head, so may need to do some testing...)

     

    Cheers,

    /Dirk

  • Sean 141 posts 179 karma points
    Apr 14, 2011 @ 11:29
    Sean
    0

    Hi Dirk, Thanks for that. It worked like a treat.

    Sean

Please Sign in or register to post replies

Write your reply to:

Draft