Copied to clipboard

Flag this post as spam?

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


  • Lewis Smith 211 posts 620 karma points c-trib
    Apr 18, 2018 @ 16:17
    Lewis Smith
    0

    Programmatically set unpublish date

    Hi all,

    I'm trying to set the unpublish date to a node programmatically but im hitting an issue.

    Here is the code i have and im not sure why its not working:

    var c = Services.ContentService.GetById(1214);
    c.SetValue("_umb_expiredate", DateTime.Now.AddMonths(1));
    Services.ContentService.SaveAndPublishWithStatus(c);
    

    I'm getting the error of No PropertyType exists with the supplied alias: _umb_expiredate but this property does exist but its a default umbraco one...

    Anyone know where im going wrong?

    Thanks, Lewis

  • Anders Bjerner 487 posts 2996 karma points MVP 8x admin c-trib
    Apr 18, 2018 @ 17:18
    Anders Bjerner
    1

    Hi Lewis,

    IContent has an ExpireDate property with the following description:

    Gets or Sets the date the Content should expire and thus be unpublished

    So given your code example, it ought to be something like this:

    var c = Services.ContentService.GetById(1214);
    c.ExpireDate = DateTime.Now.AddMonths(1);
    Services.ContentService.SaveAndPublishWithStatus(c);
    

    Hope that helps ;)

  • Lewis Smith 211 posts 620 karma points c-trib
    Apr 18, 2018 @ 18:12
    Lewis Smith
    0

    Hi Anders,

    That looks good! I will give that a go tomorrow morning when i get back into the office!

    I will let you know how i get on!

    Thanks, Lewis

  • 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