Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
Sean,you should use a recursive approach then...
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
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
Hi Dirk, Thanks for that. It worked like a treat.
Sean
is working on a reply...
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.
Continue discussion
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
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
Hi Dirk, Thanks for that. It worked like a treat.
Sean
is working on a reply...
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.