Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • David F. Hill 122 posts 242 karma points
    Feb 24, 2011 @ 17:40
    David F. Hill
    0

    Get Parent Node using C# (4.6.1)

    Hello,

    I'm having difficulty with the new umbraco.NodeFactory.Node class.

    Previously (using umbraco.presentation.nodeFactory), I was able to get the parent node like this:

    Node n = new Node(1234);
    Node p = n.Parent;

    Doing that in ver 4.6.1 (using umbraco.NodeFactory.Node) gives me this error:

    "Cannot implicitly convert type 'umbraco.interfaces.INode' to 'umbraco.NodeFactory.Node'."

    I could go back to using umbraco.presentation.nodeFactory.Node - but I try to avoid using depricated classes.

    Any help is appreciated.

    Thanks,

    David Hill

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Feb 24, 2011 @ 18:00
    Tom Fulton
    1

    Hi,

    Not sure why it returns INode instead of Node, but as a workaround I've used

    Node n = new Node(1234);
    Node p = new Node(n.Parent.Id);

    -Tom

  • David F. Hill 122 posts 242 karma points
    Feb 24, 2011 @ 23:25
    David F. Hill
    0

    Hi Tom,

    That sould work. Thanks for the help.

    David

  • nima 18 posts 38 karma points
    Dec 31, 2012 @ 12:35
    nima
    0

    I use an extension method:

    public static Node ParentNode(this Node node)
    {
        return new Node(node.Parent.Id);
    }

    but getting a simple parent node shouldn't be this difficult.

Please Sign in or register to post replies

Write your reply to:

Draft