More in this section
Blogs RSS feed

How to Publish Content Items in the Past

by Slavo Ingilizov

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.Lifecycle.PublishWithSpecificDate(item, pubDate);

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

    n =>
        n.Title = "Sample item in past";
        n.UrlName = "sample-item-in-past";
    .Publish(new DateTime(1978, 4, 15))

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.


Leave a comment
  1. Jack May 14, 2013
    This doesn't work.  If I set the publication date in the past, the item  never gets published.
  2. Jack May 14, 2013
    This doesn't work.  If I set the publication date in the past, the item  never gets published.
  3. Syed Ahsan May 26, 2014
    Also not working for me, I am using Sitefinity 5.2 :)
  4. Syed Ahsan May 26, 2014
    In my case it is working for default language(en) but if any news exist in Arabic but not in English then this problem occurs.
  5. Taha Jul 15, 2014
    This does not work and remains "scheduled for publication" and does not gets published.
  6. Neil Nov 17, 2014
    The Publish method does not have an overload that includes a DatTime param...
  7. Uttam Kumar May 08, 2015


    After doing lot of research for hours, following code did work for me and I'm on Sitefinity version 8.0.

    private void CreateBlogPost(Guid blogPostId, Guid parentBlogId, Lstring blogPostTitle, Lstring blogPostContent, string postDate, string authorName, Listcategories)        {            var masterBlogPost = BlogsManager.GetBlogPosts().Where(item => item.Id == blogPostId).FirstOrDefault();            if (masterBlogPost == null)            {                //The Blogs item is created as a master. The masterBlogPostId is assigned to the master.                masterBlogPost = BlogsManager.CreateBlogPost(blogPostId);                //The item needs to be checked out so we can pass it to WorkflowManager for scheduling                var tempBlogPost = BlogsManager.CheckOut(masterBlogPost) as BlogPost;                //Set the parent blog.                Blog blog = BlogsManager.GetBlogs().Where(b => b.Id == parentBlogId).SingleOrDefault();                tempBlogPost.Parent = blog;                //Set the properties of the blog post.                                tempBlogPost.Title = blogPostTitle;                tempBlogPost.Content = blogPostContent;                //custom field                tempBlogPost.SetValue("AuthorName", authorName);                tempBlogPost.DateCreated = DateTime.Parse(postDate);                tempBlogPost.PublicationDate = DateTime.Parse(postDate);                tempBlogPost.ExpirationDate = null;                //tempBlogPost.LastModified = DateTime.Parse(postDate);                tempBlogPost.UrlName = Regex.Replace(blogPostTitle.ToLower(), @"[^\w\-\!\$\'\(\)\=\@\d_]+", "-");                //assign blog post to taxons                if (categories != null && categories.Any())                {                    foreach (var category in categories)                    {                        if (!string.IsNullOrEmpty(category))                        {                            var categoryId = GetCategoryId(category);                            tempBlogPost.Organizer.AddTaxa("Category", categoryId);                        }                    }                }                //Recompiles and validates the url of the blog.                BlogsManager.RecompileAndValidateUrls(tempBlogPost);                //check-in to update master copy                masterBlogPost = BlogsManager.Lifecycle.CheckIn(tempBlogPost) as BlogPost;                DateTime postPublishDate = DateTime.MinValue;                if (DateTime.TryParse(postDate, out postPublishDate))                {                    BlogsManager.Lifecycle.PublishWithSpecificDate(masterBlogPost, postPublishDate);                }                else                {                    //Publish the Blogs item. The published version acquires new ID.                    var bag = new Dictionary();                    bag.Add("ContentType", typeof(BlogPost).FullName);                    WorkflowManager.MessageWorkflow(blogPostId, typeof(BlogPost), null, "Publish", false, bag);                }                //Save the changes.                BlogsManager.SaveChanges();            }        }

  8. spizz Nov 27, 2015
    This doesn't work! Version 8.2 and publishing content items in the past using this method does not work.  
  9. Richard Dec 06, 2015

    I really need this to work? Anyone have ideas please?

    Uttam Kumar - if you are receiving notifications for this, please cna you get in touch? Many thanks!

  10. Andrew Apr 02, 2016
    This is absolutely ridiculous that it is this difficult to accomplish. Do you people not take into account migration scenarios?

    Leave a comment