How do I get the DateTime that a page was last published in Sitefinity?

0 votes
asked Apr 16, 2010 by travis

Here is what I have:

Dim cmsManager As New Telerik.Cms.CmsManager()
Dim currentNode As Telerik.Cms.Web.CmsSiteMapNode = CType(SiteMap.CurrentNode, Telerik.Cms.Web.CmsSiteMapNode)
Dim currentPage As Telerik.Cms.ICmsPage = currentNode.GetCmsPage()
Dim currentPageId As Guid = currentPage.ID
Dim pageFromDb As Telerik.Cms.IPage = cmsManager.GetPage(currentPageId)

Me.LastUpdateDate = pageFromDb.DateModified

Unfortunately .DateModified returns the last time that a page was edited instead of when it was last published. I've been looking through the documentation but I haven't been able to find any corresponding properties.

2 Answers

0 votes
answered Apr 16, 2010 by travis

Here's the code I'm using now, it seems to be getting the correct date on Publish:

Dim cmsManager As New Telerik.Cms.CmsManager()
Dim currentPageId As New Guid(SiteMap.CurrentNode.Key)
Dim pageFromDb As Telerik.Cms.IPage = cmsManager.GetPage(currentPageId, False)
Dim staged As Telerik.Cms.IStagedPage = pageFromDb.GetVersion(pageFromDb.Version)

Me.LastUpdateDate = staged.DateModified

I'm not sure if there's a better way to do it though.

0 votes
answered Sep 15, 2017 by ho-chia-leung

For version 10, I'm using the following code:

var node = SiteMapBase.GetActualCurrentNode();
var itemVersions = VersionManager.GetManager().GetItemVersionHistory(node.PageId);
var lastPublishedItem = itemVersions.Where(i => i.IsLastPublishedVersion).FirstOrDefault();
var lastPublishedDate = lastPublishedItem.LastModified.ToString("dd MMMM yyyy");

I wish there's a more straight forward way to do this..

Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter