在 Razor 中更新 Umbraco 文档的 CreateDateTime?
Update an Umbraco document's CreateDateTime in Razor?
我正在尝试将 CreateDateTime
更改为 node/document,但它似乎没有任何效果。这就是我想要做的:
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
有 get/set,所以它应该有效? 运行 代码通过断点,它更新了 CreateDateTime
,但是带有 save/publish 的东西似乎将它还原了?
您的代码已被弃用,因此您需要在 umbraco 中使用 "new" 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);
我正在尝试将 CreateDateTime
更改为 node/document,但它似乎没有任何效果。这就是我想要做的:
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
有 get/set,所以它应该有效? 运行 代码通过断点,它更新了 CreateDateTime
,但是带有 save/publish 的东西似乎将它还原了?
您的代码已被弃用,因此您需要在 umbraco 中使用 "new" 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);