API to schedule an unpublish

Posted by Community Admin on 04-Aug-2018 12:34

API to schedule an unpublish

All Replies

Posted by Community Admin on 24-Oct-2014 00:00


 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?!

Posted by Community Admin on 29-Oct-2014 00:00

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;
// 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.

Nikola Zagorchev
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

This thread is closed