English 中文(简体)
How do I get the DateTime that a page was last published in Sitefinity?
原标题:

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.

最佳回答

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.

问题回答

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





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签