如何在sitefinity中更新NewsItem.LastModified?

像标题一样,我的代码确实在sitefinity文档中流动。 https://www.progress.com/documentation/sitefinity-cms/for-developers-edit-content部分通过版本ID修改项目。 它工作正常,但我尝试修改newsItem =>“ LastModified”,它会自动更新当前日期。

private void ModifyItemByLiveIDNativeAPI(Guid liveId)
{
    NewsManager manager = NewsManager.GetManager();
    NewsItem live = manager.GetNewsItems().Where(newsItem => newsItem.Id == liveId).FirstOrDefault();

    if (live != null)
    {
        //Edit the item to get the master version.
        NewsItem master = manager.Lifecycle.Edit(live) as NewsItem;

        //Check out the master to get a temp version.
        NewsItem temp = manager.Lifecycle.CheckOut(master) as NewsItem;

        //Make the modifications to the temp version.
        temp.Title = "New Title";
        temp.LastModified = new DateTime(2011,1,1);

        //Checkin the temp and get the updated master version. 
        //After the check in the temp version is deleted.
        master = manager.Lifecycle.CheckIn(temp) as NewsItem;

        manager.SaveChanges();

        //Publish the news item.
        var bag = new Dictionary<string,string>();
        bag.Add("ContentType",typeof(NewsItem).FullName);
        WorkflowManager.MessageWorkflow(master.Id,typeof(NewsItem),null,"Publish",false,bag);
   }
}

标题=>更新。但是temp.LastModified =>自动更新为curentdate。 我不知道为什么,我在Google上搜索LastModified更改,但没有结果。谢谢

lanshushumanyouji 回答:如何在sitefinity中更新NewsItem.LastModified?

CheckIn方法在内部更新LastModified属性,因此请尝试在 CheckIn之后直接在主服务器上设置LastModified。

master = manager.Lifecycle.CheckIn(temp) as NewsItem;

master.LastModified = xxx;

manager.SaveChanges();
,

如果在从其他平台导入时希望“追溯日期”新闻,则可能要更新temp.PublicationDate而不是最近一次修改。

,

我现在不知道为什么,但是每次我调用savechange()时。 lastModify自动更新,我认为它具有站点限制功能。 我找到另一种方法来控制我的问题。谢谢大家!

本文链接:https://www.f2er.com/3140286.html

大家都在问