API to schedule an unpublish
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?!
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);