Modify News Publication Date
Can you please tell me how can I modify the publication date of the news items?
I allowed the PublishDate to visible from custom field options and it is displaying on the edit mode of news but when I update the publish date it does not update.
I am using sitefinity 4.1 SP3.
Can you please reply ASAP.
Thanks!
Hello Waqar,
You can modify the publication date of the news items programmatically. Please consider the bellow sample:
var newsAll = App.WorkWith()
.NewsItems()
// .Where(nI => nI.Status == ContentLifecycleStatus.Live)
.ForEach(nI =>
var val = nI.GetValue("NewsDate").ToString();
var ss = DateTime.Parse(val);
nI.PublicationDate = ss;
nI.DateCreated = ss;
)
.SaveAndContinue();
HI !
Thanks for the reply,
I run this code but foreach loop I am getting following error
" An item with the URL '/2011/09/09/-بنك-دبي-الإسلامي-و-الأردن-دبي-كابيتال-و-دبي-انترناشونال-' already exists."
Can you please help me on this? I have more than 200 news I can't repopulate them.
Please come up with some solution.
Hi Waqar,
The sample code that I have provided you with is a solution on how to achieve the desired results using the API, if you do not intend on having a custom field from the backdating process, then you can simply pass a valid date to the code and set the PublicationDate/DateCreated accordingly.
You also have the option to upgrade to our 4.2 SP1 release, which contains this functionality built - in the system.
Kind regards,
Victor Velev
the Telerik team