在Umbraco 11中以编程方式设置内容计划安排。

huangapple go评论57阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2023年6月5日 14:58:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76404115.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定