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

后端 未结 2 2120
走了就别回头了
走了就别回头了 2021-01-19 02: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 Pag

2条回答
  •  独厮守ぢ
    2021-01-19 02:55

    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 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 :)

提交回复
热议问题