英文:
Set content schedule of content programmatically in Umbraco 11
问题
我正在尝试设置Umbraco 11中内容的内容计划,但我无法让它起作用。我找不到与Umbraco 11相关的任何参考。
这是迄今为止我的代码。
ContentSchedule sched = new ContentSchedule(doc.Key, "", expirationDate, ContentScheduleAction.Expire);
var contentScheduleCollection = new ContentScheduleCollection();
contentScheduleCollection.Add(sched);
contentService.Save(doc, contentSchedule: contentScheduleCollection);
这段代码运行没有错误,但计划没有反映在内容上。
英文:
I am trying to set the content schedule of a content in Umbraco 11 but I just can't get it to work. I can't find any reference relevant to Umbraco 11.
This is my code so far.
ContentSchedule sched = new ContentSchedule(doc.Key, "", expirationDate, ContentScheduleAction.Expire);
var contentScheduleCollection = new ContentScheduleCollection();
contentScheduleCollection.Add(sched);
contentService.Save(doc, contentSchedule: contentScheduleCollection);
This code runs with no errors but the schedule is not reflecting on the content.
答案1
得分: 0
我找到了这个提及,说你也可以这样做
contentService.PersistContentSchedule(doc, contentScheduleCollection);
最新版本和版本11的源代码都表明这个方法存在,至少应该做一些事情...
英文:
Did you figure something out?
I found this mention, saying that you can also do
contentService.PersistContentSchedule(doc, contentScheduleCollection);
Source code for both the latest version and version 11 suggests that the method exists and should at least do something ...
答案2
得分: 0
以下是翻译好的部分:
"To anyone who has encountered this, the solution is to not initialize ContentSchedule with the doc.key
Here's the working code.
ContentSchedule sched = new ContentSchedule("", expirationDate, ContentScheduleAction.Expire);
var contentScheduleCollection = new ContentScheduleCollection();
contentScheduleCollection.Add(sched);
contentService.Save(doc, contentSchedule: contentScheduleCollection);"
英文:
To anyone who has encountered this, the solution is to not initialize ContentSchedule with the doc.key
Here's the working code.
ContentSchedule sched = new ContentSchedule("", expirationDate, ContentScheduleAction.Expire);
var contentScheduleCollection = new ContentScheduleCollection();
contentScheduleCollection.Add(sched);
contentService.Save(doc, contentSchedule: contentScheduleCollection);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论