Umbraco - Finding Root Node in C#

The rootnode is always available as:

var rootNode = new Node(-1);

Update for Umbraco 7 (may work in earlier versions too)

@{
    var siteroot = CurrentPage.AncestorOrSelf(1);
}

For further info, check out the documentation -> http://our.umbraco.org/Documentation/Reference/Querying/DynamicNode/Collections


Update for Umbraco 6+

public static IPublishedContent GetRootNode()
{
    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    var rootNode = umbracoHelper.TypedContentSingleAtXPath("//root"));

    return rootNode;
}

This just takes a document type alias and finds the root node as IPublishedContent using the current Umbraco context. UmbracoHelper gives you quite a few options off this also.

Tags:

C#

Umbraco