C# Umbraco - 以编程方式通过 ID 获取节点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/974696/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:38:14  来源:igfitidea点击:

Umbraco - Get Node by ID programmatically

c#umbraco

提问by autonomatt

Running Umbraco 4x I am creating a helper method in C# that I can recursively call to create child categories of a particular node (category).

运行 Umbraco 4x 我正在 C# 中创建一个辅助方法,我可以递归调用它来创建特定节点(类别)的子类别。

The method takes a parentNodeID as a parameter. I need to retrieve the properties of that parent node. I know I can use the static method Node.GetCurrent() but I'm looking for something like Node.GetNodeById(parentNodeID).

该方法采用 parentNodeID 作为参数。我需要检索该父节点的属性。我知道我可以使用静态方法 Node.GetCurrent() 但我正在寻找类似 Node.GetNodeById(parentNodeID) 的东西。

I just can't see where this method lives. I know there is the umbraco.library.getNodeXMLbyId method, but does that give me the name property of the node?

我只是看不出这种方法在哪里。我知道有 umbraco.library.getNodeXMLbyId 方法,但这是否给了我节点的 name 属性?

Me Umbraco N00b :)

我 Umbraco N00b :)

采纳答案by Samuel Hyman

You can just do

你可以做

var node = new Node(nodeId).

Took me a while to find it too!

我也找了好久才找到!

回答by Luke Alderton

You can also do

你也可以这样做

Document doc = new Document(nodeId)

This works the same as Nodebut gets the values straight from the database instead of the XML cache. Use this if you're going to be updating the documents property values.

这与Node直接从数据库而不是 XML 缓存中获取值相同。如果您要更新文档属性值,请使用此选项。

回答by Ankit Agrawal

Use this

用这个

umbraco.NodeFactory.Node headerNode = uQuery.GetNode(NodeId);

add namespace

添加命名空间

using umbraco.NodeFactory;