+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / API to schedule an unpublish

API to schedule an unpublish

2 posts, 0 answered
  1. Daniel
    Daniel avatar
    13 posts
    Registered:
    30 Jul 2014
    24 Oct 2014
    Link to this post

    Hello,

     I'm trying to find documentation on how to schedule the unpublishing of a news item via the API.

     I presume it involves WorkflowManager but no idea how to go about it. Any pointers?!

  2. Nikola Zagorchev
    Nikola Zagorchev avatar
    424 posts
    Registered:
    24 Nov 2016
    29 Oct 2014
    Link to this post
    Hi Daniel,

    You can use the following code snippet in order to schedule unpublish of a news item:
    NewsManager manager = NewsManager.GetManager();
    // get item master version
                var newsItem = manager.GetNewsItems()
                    .Where(g => g.Title == "news1" && g.Status == ContentLifecycleStatus.Master).FirstOrDefault();
     
                newsItem.PublicationDate = DateTime.Now.AddMinutes(1).ToLocalTime();
                newsItem.ExpirationDate = DateTime.Now.AddMinutes(3).ToLocalTime(); // set expiration
                CultureInfo en = new CultureInfo("en"); // get correct culture
                NewsItem temp = manager.Lifecycle.CheckOut(newsItem, en) as NewsItem;
     
                manager.SaveChanges();
    // schedule
                var bag = new Dictionary<string, string>();
                bag.Add("ContentType", typeof(NewsItem).FullName);
                WorkflowManager.MessageWorkflow(newsItem.Id, typeof(NewsItem), manager.Provider.Name, "Schedule", true, bag);

    I have tested it on Sitefinity 7.2. I hope it is useful.

    Regards,
    Nikola Zagorchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
2 posts, 0 answered