Umbraco 4.6+ - 如何在 C# 中通过文档类型获取所有节点? [英] Umbraco 4.6+ - How to get all nodes by doctype in C#?
本文介绍了Umbraco 4.6+ - 如何在 C# 中通过文档类型获取所有节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用 Umbraco 4.6+,有没有办法在 C# 中检索特定文档类型的所有节点?我一直在寻找 umbraco.NodeFactory
命名空间,但还没有找到任何有用的东西.
Using Umbraco 4.6+, is there a way to retrieve all nodes of a specific doctype in C#? I've been looking in the umbraco.NodeFactory
namespace, but haven't found anything of use yet.
推荐答案
我今天刚做这个,类似于下面的代码应该可以工作(使用 umbraco.presentation.nodeFactory),使用 -1 的 nodeId 调用它以获得网站的根节点,让它工作它的方式:
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);
}
}
这篇关于Umbraco 4.6+ - 如何在 C# 中通过文档类型获取所有节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文