Would following code work to loop through the node-hierarchy and collect the nodes of type Product?
[System.Web.Services.WebMethod] public static string[] GetNames(string prefixText) { List<String> namn = new List<String>(); Node node = new umbraco.presentation.nodeFactory.Node(1079); foreach (Node child in node.Children) { if (child.NodeTypeAlias == "Product") { namn.Add(child.Name); }
foreach (Node child2 in child.Children) { if (child.NodeTypeAlias == "Product") { namn.Add(child2.Name); }
foreach (Node child3 in child.Children) { if (child.NodeTypeAlias == "Product") { namn.Add(child3.Name); }
foreach (Node child4 in child.Children) { if (child.NodeTypeAlias == "Product") { namn.Add(child4.Name); }
Would this use of nodefactory work?
I have a contentstructure like following example:
Product(ID 1079)
Product category1
Product category level2
Product category level3
Product
Product category level3
Product
Product
Product category level2
Product
Would following code work to loop through the node-hierarchy and collect the nodes of type Product?
[System.Web.Services.WebMethod]
public static string[] GetNames(string prefixText)
{
List<String> namn = new List<String>();
Node node = new umbraco.presentation.nodeFactory.Node(1079);
foreach (Node child in node.Children)
{
if (child.NodeTypeAlias == "Product")
{
namn.Add(child.Name);
}
foreach (Node child2 in child.Children)
{
if (child.NodeTypeAlias == "Product")
{
namn.Add(child2.Name);
}
foreach (Node child3 in child.Children)
{
if (child.NodeTypeAlias == "Product")
{
namn.Add(child3.Name);
}
foreach (Node child4 in child.Children)
{
if (child.NodeTypeAlias == "Product")
{
namn.Add(child4.Name);
}
}
}
}
}
return namn.ToArray();
}
I think Linq2Umbraco is perfect for this: http://www.aaron-powell.com/linq-to-umbraco-overview http://www.aaron-powell.com/training-videos
Jeroen
Frederik,
You could even make an examine search for type product that would be even quicker.
Regards
Ismail
Why not go with a recursive function, that'd be a lot more logical than nested loops on top of nested loops
Thanks for the insightful input, things are working properly,
is working on a reply...