More in this section

Forums / General Discussions / News customization

News customization

2 posts, 0 answered
  1. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    09 May 2011
    Link to this post
    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
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    28 Aug 2017
    12 May 2011
    Link to this post
    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
2 posts, 0 answered