1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / News Publication Date

News Publication Date

5 posts, 0 answered
  1. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    13 Mar 2012
    Link to this post
    I have a new site an must copy over the news from the past years.

    Am I wrong or is there still no way to set a publication date on News.

    How do you sort news by publication date?

    Markus
  2. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    14 Mar 2012
    Link to this post
    Anyone?

    Markus
  3. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    16 Mar 2012
    Link to this post
    Hello Markus,

    You can check this blog post out which explains how you can publish any content item in Sitefinity with a past date, I believe you might find it useful. I've also prepared a small sample for you which you can use directly in code if you want to schedule your news item:
    public void ScheduleNewsItem(string newsTitle, string newsContent, DateTime publicationDate, DateTime expirationDate)
           {
               NewsManager nManager = NewsManager.GetManager();
               var newsItem = nManager.CreateNewsItem();
     
               newsItem.Title = newsTitle;
               newsItem.Content = newsContent;
               SummarySettings newsSummarySettings = new SummarySettings(SummaryMode.Words, 20, false, false);
               newsItem.Summary = SummaryParser.GetSummary(newsContent, newsSummarySettings);
               newsItem.AllowComments = false;
               newsItem.Visible = true;
               //You need to set the UrlName and replace any special characters,  the manager will take care of recompiling the item URL
               newsItem.UrlName = Regex.Replace(newsItem.Title.ToLower(), UrlNameCharsToReplace, UrlNameReplaceString);
               newsItem.PublicationDate = publicationDate;
               newsItem.ExpirationDate = expirationDate;
               //The item needs to be chacked out so we can pass it to WorkflowManager for scheduling
               nManager.CheckOut(newsItem);
               nManager.SaveChanges();
     
               var bag = new Dictionary<string, string>();
               bag.Add("ContentType", typeof(NewsItem).FullName);
               WorkflowManager.MessageWorkflow(newsItem.Id, typeof(NewsItem), null, "Schedule", true, bag);
           }


    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    16 Mar 2012
    Link to this post
    Dear Boyan

    Thanks for the feedback. It's ok to have a workaround but I would never have guessed to use a publish unpublish date to set a news date.

    Markus
  5. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    16 Mar 2012
    Link to this post
    Hi Markus,

    Thank you for getting back to me. Maybe I didn't get your question correctly, can you please elaborate in some more details on the exact use case scenario that you're going to implement, as we have extended the functionality for setting Content items publication date to include almost all possible scenarios, and will be glad to assist you in using it.

    Regards,
    Boyan Barnev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
5 posts, 0 answered