How to get the published timestamp of a page or component using SDL Tridion TOM.NET API

拈花ヽ惹草 提交于 2019-12-19 19:05:35

问题


I'm trying to get hold of the published timestamp for a given page or component to a given target using the TOM.NET API. It isn't immediately obvious under the Page or Component object, can someone point me in the right direction?


回答1:


You can use the PublishEngine.GetPublishInfo(IdentifiableObject) method for that, it returns a collection of PublishInfo objects which holds the dates and other (publish) information available for the given item.




回答2:


Thanks to Bart's answer above, I've knocked up the following rough code. It's not about performance as this is a proof of concept to demo something to a customer:

// if we are in publishing mode, figure out the target we are publishing to, and get the timestamp that the page is published to this target
if (engine.PublishingContext.PublicationTarget != null)
{
  ICollection<PublishInfo> publishCollections = PublishEngine.GetPublishInfo(childPage);
  foreach (PublishInfo publishInfo in publishCollections)
  {
     if (publishInfo.PublicationTarget == engine.PublishingContext.PublicationTarget)
     {
        pageElem.SetAttribute("timestamp", publishInfo.PublishedAt.ToString());
     }
   }
}

Here you can see I already have my childPage object, and i'm adding the result to an existing page XML object (pageElem.SetAttribute("timestamp", publishInfo.PublishedAt.ToString())) - so if using this snippet look out for these items :)



来源:https://stackoverflow.com/questions/10092156/how-to-get-the-published-timestamp-of-a-page-or-component-using-sdl-tridion-tom

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!