Just want PUBLISHED pages in SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
I am working on a simple user control's code behind and need ONLY the published front end page nodes. I thought I would get that from the following, but I was wrong. It also returns unpublished and draft pages.
var provider = SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
var publishedPages = App.WorkWith().Pages().ThatArePublished().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Where(p => p.ShowInNavigation ==
true
).OrderBy(p => p.Ordinal);
Here is the solution:
Synopsis:
// This is the entire sitemap
var provider = SiteMapBase.GetSiteMapProvider(
"FrontendSiteMap"
);
// Get the current page cast as a Sitefinity PageSiteNode (Telerik type)
// Without the cast, currentNode would be of type SiteMapNode (Microsoft type)
// It may be confusing because those types are so closely named
PageSiteNode currentNode = (PageSiteNode)provider.CurrentNode;
// Now you can do what you want with the node
// For example, you can ask if it is published like this:
if
(currentNode.IsPublished())
// do something
// You can also get its child nodes as a SiteMapNodeCollection
if
(currentNode.HasChildNodes)
// a SiteMapNodeCollection (Microsoft type collection)
var children = currentNode.ChildNodes;
// can loop through the children, checking if each is published
// get nodes out of the collection as type PageSiteNode to have .IsPublished() available to you
foreach
(PageSiteNode node
in
children)
if
(node.IsPublished())
// do something with the published node here
Hey, is there a way to determine if the page is a redirect?