AI OnAI Off
You have to get the page out from the IContentLoader first. You can load it out as a PageData or IContent object then use the ParentLink property which will be the parent.
Example although you usually want the IContentLoader to be injected either in the constructor or using the Injected<> method.
var pageReference = ContentReference.EmptyReference; var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); var page = contentLoader.Get<IContent>(pageReference); var parentPage = contentLoader.Get<IContent>(page.ParentLink);
Here I've created a pageReference empty reference but that should be the reference of the page you're trying to get the parent of.
An alternative is to use EPiServer.IContentLoader.GetAncestors(ContentReference contentLink) then will you get all ancestors for a specific content item or EPiServer.Web.Routing.AncestorReferencesLoader.GetAncestors(ContentReference contentLink) if you only want the references to the ancestors.
Hi guys,
I have a ContentReference object, which refers to a page in my content tree, I want to get the ContentReference of the parent node?
How can I do this?