【问题标题】:Update an Umbraco document's CreateDateTime in Razor?在 Razor 中更新 Umbraco 文档的 CreateDateTime?
【发布时间】:2015-03-27 15:46:48
【问题描述】:

我正在尝试更改节点/文档的CreateDateTime,但它似乎没有任何效果。这就是我想要做到的:

dynamic node = new DynamicNode(1065);                     
Document n = new Document(node.Id);
n.CreateDateTime = node.articlePublishedDate;
n.Save();
n.Publish(new umbraco.BusinessLogic.User(0));
umbraco.library.UpdateDocumentCache(n.Id);  

我是否以正确的方式处理这件事?而且,我假设它甚至可以改变是正确的吗? API 似乎表明CreateDateTime 具有获取/设置,所以它应该可以工作吗?使用断点运行代码,它会更新CreateDateTime,但保存/发布的某些内容似乎将其还原?

【问题讨论】:

  • 这是什么版本的umbraco?
  • @MortenOC 这是 Umbraco 7.1.8。

标签: razor umbraco umbraco7


【解决方案1】:

您的代码已被弃用,因此您需要使用 umbraco 中的“新”ContentService: https://our.umbraco.org/documentation/Reference/Management-v6/Services/ContentService

应该是这样的:

var cs = Services.ContentService;
var node = cs.GetById(1065);
node.CreateDate = DateTime.Now;
cs.SaveAndPublish(node);

【讨论】:

  • 谢谢@MortenOC。我似乎无法让SetValue()createDateTimeCreateDateTime 一起使用,但只需使用node.CreateDate 就可以了!
  • @edparry 酷!我不记得 CreateDate 是否有二传手。但是很好用!我已经更新了答案。
猜你喜欢
  • 1970-01-01
  • 2014-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-09
  • 1970-01-01
  • 1970-01-01
  • 2013-01-27
相关资源
最近更新 更多