I was just doing this today, something like the below code should work (using umbraco.presentation.nodeFactory), call it with a nodeId of -1 to get the root node of the site and let it work it's way down:
private void DoSomethingWithAllNodesByType(int NodeId, string typeName)
{
var node = new Node(nodeId);
foreach (Node childNode in node.Children)
{
var child = childNode;
if (child.NodeTypeAlias == typeName)
{
//Do something
}
if (child.Children.Count > 0)
GetAllNodesByType(child, typeName);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…