Just want PUBLISHED pages in SiteMapBase.GetSiteMapProvider(

Posted by Community Admin on 03-Aug-2018 01:16

Just want PUBLISHED pages in SiteMapBase.GetSiteMapProvider("FrontendSiteMap");

All Replies

Posted by Community Admin on 03-Apr-2012 00:00

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");

Any idea how to either:
a) filter this provider for only published SiteMapNodes (or functional equivalent) 

or 

b) determine if a given SiteMapNode (or functional equivalent) from this provider is published.

Is there a Sitefinity wrapper for these objects that can determine if a given node is published? I know there is a fluent syntax* to get published pages, but frankly without good examples or published source, I cannot do as much with the collection that is returned. It is much more cumbersome to select subsets of a query than to just navigate the node tree.

*This is the classic example of using fluent syntax to get a collection of published pages:
var publishedPages = App.WorkWith().Pages().ThatArePublished().LocatedIn(Telerik.Sitefinity.Fluent.Pages.PageLocation.Frontend).Where(p => p.ShowInNavigation == true).OrderBy(p => p.Ordinal);

Posted by Community Admin on 04-Apr-2012 00:00

Here is the solution:

Synopsis:

SiteMapNodes pulled from the provider do not have the Sitefinity concept of "Is Published" or not. It is a Microsoft base type. However, you can cast a SiteMapNode to a Sitefinity type called "PageSiteNode", which is functionally equivalent, but also includes additional Sitefinity information such as whether or not the page is published.

Sample:

// 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
    
 

Posted by Community Admin on 18-Jul-2012 00:00

Hey, is there a way to determine if the page is a redirect?

This thread is closed