News customization

Posted by Community Admin on 03-Aug-2018 07:57

News customization

All Replies

Posted by Community Admin on 09-May-2011 00:00

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

Posted by Community Admin on 12-May-2011 00:00

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();
I hope you find this information useful, if you need any further assistance please let us know.

Best wishes,
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

This thread is closed