How to Publish Content Items in the Past

September 28, 2011 Digital Experience

As usual, we’ve packed a lot of fixes and improvements in the just released 4.2 SP1 of Sitefinity. If you still haven’t checked it out, go download it from your account. With this blog post, I want to highlight a feature we’ve implemented that was requested a lot. From now on, you can publish any content in Sitefinity with a date in the past.

Lots of people asked us to implement this, and we listened. A common scenario we’ve heard about is importing content from an existing news site into Sitefinity, and keeping the dates of news articles. This is now possible.

When creating an item, instead of clicking the Publish button directly, you can choose another option from the “More Actions” menu:

This would bring up a dialog, where you can select any date for publishing the news item, including ones in the past.

Publishing items in the past using the API

Although this is handy, I admit there will be a lot of scenarios, where this work will not be done through the user interface. Many people have written custom code to import content using the Sitefinity API. We’ve also made it very easy to specify a past date for items created through code.

var pubDate = new DateTime(1978, 4, 15);
var manager = NewsManager.GetManager();
var item = manager.CreateNewsItem();
item.Title = "News item in the past";
item.UrlName = "past-news";
item.Content = "This item is created through the native API";
manager.RecompileItemUrls(item);
manager.Lifecycle.PublishWithSpecificDate(item, pubDate);
manager.SaveChanges();

And also, here’s how you can do the same using the fluent API:

App.WorkWith().AnyContentItem<NewsItem>().CreateNew().Do(
    n =>
    {
        n.Title = "Sample item in past";
        n.UrlName = "sample-item-in-past";
    })
    .Publish(new DateTime(1978, 4, 15))
    .SaveChanges();

Go ahead and try this new feature. We are open to other suggestions to include in the next releases. The more you vote on items in PITS, the faster you get them.

The Progress Team