autonomatt
autonomatt

Reputation: 4433

Umbraco - Get Node by ID programmatically

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).

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).

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?

Me Umbraco N00b :)

Upvotes: 24

Views: 25620

Answers (3)

Ankit Agrawal
Ankit Agrawal

Reputation: 2454

Use this

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

add namespace

using umbraco.NodeFactory;

Upvotes: 1

Luke Alderton
Luke Alderton

Reputation: 3296

You can also do

Document doc = new Document(nodeId)

This works the same as Node but 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.

Upvotes: 0

Samuel Jack
Samuel Jack

Reputation: 33270

You can just do

var node = new Node(nodeId).

Took me a while to find it too!

Upvotes: 42

Related Questions