C# 如何在sitefinity中更新NewsItem.LastModified?

C# 如何在sitefinity中更新NewsItem.LastModified?,c#,backend,sitefinity,C#,Backend,Sitefinity,和标题一样,我在sitefinity文档中也使用了这段代码。 按项目版本的id部分修改项目。 它工作得很好,但我尝试修改newsItem=>的“LastModified”,它会自动更新当前日期 private void ModifyItemByLiveIDNativeAPI(Guid liveId) { NewsManager manager = NewsManager.GetManager(); NewsItem live = manager.GetNewsItems().Wh

和标题一样,我在sitefinity文档中也使用了这段代码。 按项目版本的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);
   }
}
private void ModifyItemByLiveIDNativeAPI(Guid liveId)
{
NewsManager=NewsManager.GetManager();
NewsItem live=manager.GetNewsItems().Where(NewsItem=>NewsItem.Id==liveId.FirstOrDefault();
如果(活动!=null)
{
//编辑项目以获取主版本。
NewsItem master=manager.Lifecycle.Edit(实时)为NewsItem;
//检查主版本以获得临时版本。
NewsItem temp=manager.Lifecycle.CheckOut(主)作为NewsItem;
//对临时版本进行修改。
临时标题=“新标题”;
temp.LastModified=新日期时间(2011,1,1);
//签入temp并获取更新的主版本。
//签入后,临时版本将被删除。
master=manager.Lifecycle.CheckIn(临时)作为新闻项;
SaveChanges();
//发布新闻。
var bag=新字典();
bag.Add(“ContentType”,typeof(NewsItem).FullName);
WorkflowManager.MessageWorkflow(master.Id,typeof(newItem),null,“Publish”,false,bag);
}
}
标题=>更新。但是temp.LastModified=>自动更新到currentDate。
我不知道为什么,我在谷歌上搜索更改LastModified,但没有结果。谢谢,签入方法会在内部更新LastModified属性,因此请尝试在签入后直接在主机上设置LastModified属性


如果您在从其他平台导入时查看“back date”新闻项,您可能希望更新temp.PublicationDate not last modified。

我现在不知道为什么,但每次调用savechange()。lastModify自动更新我认为这是sitefinity的一个特性。
我找到另一种方法来控制我的问题。谢谢大家

嗨。我正在更新文件Global.asx.cs。当newItem.savechange()=>EventHub.Subscribe(DataEventHandler)时;它转到DataEventHandler,我在这里编写了代码。我用你的方式,但在经理之后。SaveChanges();master.LastModified=>comback to current date。您能否在问题中提供完整的代码,包括global.asax代码?还有,这是什么Sitefinity版本?检查后。每次我更改某些内容并在任何地方调用savechange()时都会发生这种情况。我认为savechange()自动更新LastModified。这就引出了一个问题-为什么要更改此属性?
master = manager.Lifecycle.CheckIn(temp) as NewsItem;

master.LastModified = xxx;

manager.SaveChanges();