How to Publish Content Items in the Past

How to Publish Content Items in the Past

Posted on September 28, 2011 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

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:

moreActions

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

publishDialog

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.

progress-logo

The Progress Team

View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation