Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesper Bille Olsen 2 posts 72 karma points
    Oct 22, 2019 @ 09:00
    Jesper Bille Olsen
    0

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

  • Kevin Jump 1867 posts 11859 karma points MVP 4x c-trib
    Oct 22, 2019 @ 11:28
    Kevin Jump
    1

    Hi Jepser,

    think you have to set a content schedule

    item.ContentSchedule.Add(new ContentSchedule("*", DateTime.Now.AddDays(1), ContentScheduleAction.Expire))
    

    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.

    item.ContentSchedule.Clear(ContentScheduleAction.Expire);
    
  • Jesper Bille Olsen 2 posts 72 karma points
    Oct 22, 2019 @ 16:55
    Jesper Bille Olsen
    0

    Thank you Kevin, it worked ! :D

    This is my final code:

    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);
    
  • Mortaza Nourestani 2 posts 72 karma points
    Dec 17, 2020 @ 00:31
    Mortaza Nourestani
    0

    This is not working for me

  • Allan Kent 1 post 71 karma points
    Dec 17, 2020 @ 06:51
    Allan Kent
    0

    I can confirm, it´s working here too.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies