+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Just want PUBLISHED pages in SiteMapBase.GetSiteMapProvider("FrontendSiteMap");

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

3 posts, 0 answered
  1. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    03 Apr 2012
    Link to this post
    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);
  2. Dan Sorensen
    Dan Sorensen avatar
    256 posts
    Registered:
    13 Aug 2010
    04 Apr 2012
    Link to this post
    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
        }
     
    }

  3. Charles
    Charles avatar
    61 posts
    Registered:
    18 Jul 2012
    18 Jul 2012
    Link to this post
    Hey, is there a way to determine if the page is a redirect?
3 posts, 0 answered