News Publication Date
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
Anyone?
Markus
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);
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
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