var contentService = Services.ContentService;
var node = contentService.GetById(item.Id);
var contentsched = new ContentSchedule("*", DateTime.Now.AddDays(3), ContentScheduleAction.Expire);
node.ContentSchedule.Clear(ContentScheduleAction.Expire);
node.ContentSchedule.Add(contentsched);
contentService.SaveAndPublish(node);
Tnx for great solution. I had to modify it a bit to work on multiple language site:
var csd = new ContentScheduleCollection();
foreach (var c in node.CultureInfos)
{
csd.Add(new ContentSchedule(c.Culture, maxDate.AddDays(1), ContentScheduleAction.Expire));
}
node.ContentSchedule = csd;
Programmatically set unpublish date
I am trying to programmatically set unpublish date in Umbraco 8, but i can't seem to figure out how..
I want to do the same as answered here: https://our.umbraco.com/forum/extending-umbraco-and-using-the-api/91642-programmatically-set-unpublish-date?fbclid=IwAR0LJxj_rsZly2Kq9pTh3iTXe2a5QcLHeVEuN5esoGXQk9fplN1AMWp5bj4
But there is no expireDate in Umbraco 8
Hope someone can help :)
Hi Jepser,
think you have to set a content schedule
the tricky bit is the culture, for which I think "*" would mean all languages (it does in other places in the code base).
you might also need to clear it to ensure you not adding extras.
Thank you Kevin, it worked ! :D
This is my final code:
This is not working for me
I can confirm, it´s working here too.
Tnx for great solution. I had to modify it a bit to work on multiple language site:
For some reason, the "*" didn't work
is working on a reply...