How to get date of published page from Navigation

Posted by Community Admin on 04-Aug-2018 14:19

How to get date of published page from Navigation

All Replies

Posted by Community Admin on 20-Mar-2013 00:00

Hello,

I have a piece of code where I am rendering the nodes for my left hand side navigation. Pretty standard. Now I have also been asked to, when in preview mode, to show the menu items of the pages that will be published on the same date as per the publish date of the current page in view.

Done a few attempts and haven't yet managed to do it, so coming to the forums for help.
 I have the following.

protected void RTV1_NodeDataBound(object sender, Telerik.Web.UI.RadTreeNodeEventArgs e)
        
            //get the current node's URL
            if (e.Node.NavigateUrl.Equals(currentNodeURL))
            
                e.Node.Selected = true;
                //ensure that the parent nodes are selected
                e.Node.ExpandParentNodes();
                //force the node to expand
                e.Node.Expanded = true;
            
            //if not the selected node
            else
           
                    e.Node.Selected = false;
                    //collapse the children
                    e.Node.CollapseChildNodes();
                    //force the node property 'expanded' to false
                    e.Node.Expanded = false;
            
        

So for each node I want to get the page ID and get the publish date, how to achieve that?

Thanks,

R
        

Posted by Community Admin on 20-Mar-2013 00:00

Managed to sort it, I realised that I can actually do the following:

var provider = SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
PageSiteNode currentNode = (PageSiteNode)provider.CurrentNode;

//and then cast the current Node to a Page Site Node
currentNode = (PageSiteNode)e.Node.DataItem;

//and then I can get the publication date of the current node
var pageManager = PageManager.GetManager();
var currentNodePublishDate = pageManager.GetPageData(currentNode.PageId).PublicationDate;

The only question now is how to get the non-published pages while rendering the control. The main point is to show to the user how the site will look when the page is published. Any thoughts anyone?

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

Actually best way to do it is...

 var provider = SiteMapBase.GetSiteMapProvider("FrontendSiteMap");
                    PageSiteNode currentPageNode = (PageSiteNode)provider.CurrentNode;

                    if (currentPageNode.IsPublished())

//do something

Posted by Community Admin on 08-Apr-2013 00:00

Hello Ricardo,

As far as I underatand you'd like to check if the current page is published, and if so, execute some logic. You are right that the best way would be to use the isPublished() method. Thank you for sharing your observations with the community! 

Greetings,
Jen Peleva
the Telerik team
Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed