More in this section
Categories
Bloggers
Blogs RSS feed

How to Publish Content Items in the Past

by User Not Found

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.

58 comments

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

    Hi,

    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?
  11. Gold Storage Dubai Apr 02, 2018
    This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post.Gold Storage Dubai
  12. Military flight travel Apr 02, 2018
    I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing.Military flight travel
  13. HYDRAULIC POWER UNITS Apr 02, 2018
    Excellent information on your blog, thank you for taking the time to share with us. Amazing insight you have on this, it's nice to find a website that details so much information about different artists.HYDRAULIC POWER UNITS
  14. multiple sclerosis Apr 02, 2018
    Thank you for the update, very nice site..multiple sclerosis
  15. Elliatt Apr 02, 2018
    thanks for the tips and information..i really appreciate it..Elliatt
  16. painting cabinets Apr 02, 2018
    Thanks for the nice blog. It was very useful for me. I'm happy I found this blog. Thank you for sharing with us,I too always learn something new from your post.painting cabinets
  17. sbobet Apr 02, 2018
    You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!.sbobet
  18. generator maintenance Apr 02, 2018
    Great knowledge, do anyone mind merely reference back to itgenerator maintenance
  19. detectives en el barrio de salamanca Apr 02, 2018
    I found that site very usefull and this survey is very cirious, I ' ve never seen a blog that demand a survey for this actions, very curious...detectives en el barrio de salamanca
  20. from sacramento to sfo Apr 09, 2018
    I have recently started a blog, the info you provide on this site has helped me greatly. Thanks for all of your time & work.from sacramento to sfo
  21. DETECTIVES EN MADRID Apr 11, 2018
    I am very happy to discover your post as it will become on top in my collection of favorite blogs to visit.DETECTIVES EN MADRID
  22. DETECTIVES MADRID Apr 16, 2018
    I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people.DETECTIVES MADRID
  23. ΑΠΟΦΡΑΞΕΙΣ ΤΙΜΕΣ Apr 18, 2018
    Τα τελευταία χρόνια επεκτείναμε σταδιακά τις δραστηριότητες μας εκτός τις Αποφράξεις αποχετευτικών αγωγών και εκκενώσεις βόθρων, τώρα αναλαμβάνουμε υπεύθυνα απολυμάνσεις κτηρίων και έκδοση κοινοχρήστων, θέλοντας να προσφέρουμε ολοκληρωμένες υπηρεσίες στις κτηριακές ανάγκες.αποφραξεις
  24. Spuitkurk Apr 21, 2018
    Please continue this great work and I look forward to more of your awesome blog posts.Spuitkurk
  25. avengers Apr 23, 2018
    Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.avengers
  26. Zon Apr 23, 2018
    I was really enthousiastic when this blog was presented. Of great interest to me to read. Zonnepanelen | Warmtepomp kopen | Airco
    | Airconditioning
  27. .AGENCIA DETECTIVES PRIVADOS Apr 26, 2018
    Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.AGENCIA DETECTIVES PRIVADOS
  28. Ellena Apr 29, 2018
    This post was really magnificent. I really like the way you explain all the details here, so cute and entertaining. This is one of the best post that I’ve read so far. top 10 protein supplements
  29. Massagesalon-limburg.be Apr 29, 2018
    Thank you very much for this useful article. I like it Erotische massage
    Howdy just wanted to give you a quick heads up Massage Limburg
    I am really glad I have found this information Striptease
    I like it what you formulated here. Erotische massages
  30. firming wand May 01, 2018
    You’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!.firming wand
  31. Wordpresswebdesign.be May 03, 2018
    https://wordpresswebdesign.be likes you efforts on this subject. Wordpress website laten bouwen
  32. AGENCIA DETECTIVES MADRID May 05, 2018
    That is the excellent mindset, nonetheless is just not help to make every sence whatsoever preaching about that mather. Virtually any method many thanks in addition to i had endeavor to promote your own article in to delicius nevertheless it is apparently a dilemma using your information sites can you please recheck the idea. thanks once more.AGENCIA DETECTIVES MADRID
  33. https://www.atomicdesign.net May 07, 2018
    An interesting dialogue is price comment. I feel that it is best to write more on this matter, it may not be a taboo topic however usually individuals are not enough to talk on such topics. To the next. Cheers.https://www.atomicdesign.net
  34. Warmtepompboiler.net May 08, 2018
    What an interesting piece of information you have provided here. Thank you from Warmtepompboiler.net and Soloya.be!  Warmtepompboilershttps://www.warmtepompboiler.net/
    www.aquapura.be and Terraspro.be were cheerfull and happy enthousiastic when this blog was presented. Interesting stuff to read. | Terrasoverkappingen | Terrasoverkappingen TerrasPro| Zwembaden | Terrasoverkapping | Pergola's | Zonwering
    | Zwembaden | Pergola's | Polypropyleen zwembad | Pergola | Zwembaden | Zwembaden Le Bain D'or
    Zwembaden-lebaindor.be was happy so enthousiastic with all the Interesting stuff to read hre. Zwembad aanleggen | Zwembad bouwen | TerrasPro Terrasoverkappingen |Zonnescreens | Zwembad op maat | Polypropyleen zwembaden
    Aquapura.be Zwembaden found this a very interesting and entertaining blogarticle to read.  Zwembaden | Zwembaden Aqua Pura
      
  35. bomberman 64 May 15, 2018
    Thank you so much Love your blog..bomberman 64
  36. Sempris.be May 15, 2018
    Sempris.be really admires what you wrote down this subject.Webdesign
  37. MONIKA May 22, 2018
    Excellent and very exciting site. Love to watch. Keep Rocking.seguidores
  38. Warmtepompboiler.net May 22, 2018
    What an interesting piece of information you have provided here. Thank you from Warmtepompboiler.net and Soloya.be!  Warmtepompboilers
  39. Airco-airconditioning.be May 22, 2018
    Airco-airconditioning.be Being able to get moe info on this topic here has been mindblogging to me.. Airco | Airconditioning | Airco prijs | Airco Antwerpen | Airconditioning AntwerpenAirco Limburg | Airconditioning Limburg
  40. MONIKA May 23, 2018
    Ganhar curtidas no instagram de um modo rápido, seguro é com o site Curtidas Grátis. O melhor site para ganhar curtidas e likes no Instagram.
  41. MONIKA May 24, 2018
    I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back soon. Please check out my site as well and let me know what you think.2018 Cent Box - 2018 Cent
  42. MONIKA May 28, 2018
    Excellent and very exciting site. Love to watch. Keep Rocking.Cloud Server Windows
  43. MONIKA May 30, 2018
    Thanks for this article very helpful. thanks.Detectives España
  44. soloya.be Jun 05, 2018
    www.soloya.be was really enthousiastic when this blog was presented. Of great interest to me to read. Zonnepanelen | Zonnepanelen kopen | Zonnepanelen installateur | Warmtepomp kopen | Airco | Airconditioning | Airco installatie | Airco installateur
  45. Aquapura.be Zwembaden Jun 05, 2018
    Aquapura.be Zwembaden found this a very interesting and entertaining blogarticle to read. Zwembaden
    | Zwembaden Aqua Pura  
  46. Soloya.be Jun 05, 2018
    I was lucky to have found this blog and I found this very interesting and entertaining to read. Thank you from www.soloya.be and https://zonnepanelen-centrale.be  Zonnepanelen | Warmtepompen | Warmtepompen 
  47. Chape Jun 05, 2018
    By accident this blog was here and reading it has been epic for Chape-braspenning.be . Chape | Chapewerken  | Vloerisolatie | Isolatiechape | PUR isolatie | Akoestische vloerisolatie
  48. MONIKA Jun 06, 2018
    For over 10 years, Hair Restoration Laboratories has developed and offered to men and women the most effective dht blocking shampoos and conditioners to help reverse hair loss and regrow stronger, thicker and healthier hair. Dht blocker conditioner
  49. MONIKA Jun 07, 2018
    Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place..Detectives privados Madrid
  50. MONIKA Jun 09, 2018
    Nice to be visiting your blog again, it has been months for me. Well this article that i've been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share.t shirt printing services

    Leave a comment