Umbraco 4.6: Get Node by Version

Go To StackoverFlow.com

0

I am trying to get a previous version of a published node to do comparison to the current node. I have found Document.GetContentFromVersion but can't seem to find the equivalent in NodeFactory or a way to convert Content to a Node type. Can anyone help?

2012-04-05 17:53
by user1315940


1

There isn't an equivalent to Document.GetContentFromVersion in NodeFactory as NodeFactory gets its data from the umbraco.config cache and Document pulls it's data from the database (See Difference Between Node and Document).

You can get at the properties of a Content object the same way you would with a Document or a Node:

var old = Document.GetContentFromVersion(version);
var oldProperty = old.getProperty("propertyAlias");

For comparisons, Node:

var nodeProperty = node.GetProperty("propertyAlias");

if (oldProperty.Value == nodeProperty.Value)
{
    ...
}

Document:

var docProperty = node.getProperty("propertyAlias");
if (oldProperty.Value == docProperty.Value)
{
    ...
}
2012-04-05 19:52
by Douglas Ludlow
That's what I figured. The reason I asked was I was hoping to reuse a method which currently takes a Node type for its argument. There are several ways to skin this cat. I was just hoping it would be a simple type cast I was missing. :-) Thanks - user1315940 2012-04-05 21:09
Ads