News customization
Hi,
I using a sitefinity 4. I have a custom control to display the news item programatically. As I can not publish news with backdated, I had placed a custom field "NewsDate" which gets the date from the user. Now I need to sort this date. But through code I cannot use this date "NewsDate" as I cannot find the properties for it or assembly reference.
How to sort the news item with my custom field "NewsDate" instead of publicationDate?
Please reply ASAP.
Thanks,
sathya
Hello sathiyaseelan,
Actually it is possible to backdate your news items to the value you have specified in your custom field using the GetValue() method. Please take a look at the sample code below which sets the PublicationDate and DateCreated for all news items to the date specified in the custom filed. It'd be best to make the custom field of a DateTime type, so that users can get the advantage of the DateTime picker and also ensure the specified date would be in the correct format.
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();