+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / News control date issue

News control date issue

6 posts, 0 answered
  1. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    07 May 2011
    Link to this post
    hi,

    I am new to sitefinity 4. I have a news control in my web page. I want to show different publication date for all my news which i am creating. If i change the publication date still its not saving with that date. If i am using custom field "New date" and give with different date and also use the same in default control then am not able to sort with news date as by default it is sorting with publication date.

    So can I use custom field "newsdate" and sort this in descending order in a default news control.?
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    02 Dec 2016
    09 May 2011
    Link to this post
    Hello sathiyaseelan,

    You can use the value set in your custom field to set the news item publication date. Please take a look at the sample code below which does exactly that - it takes the value in the custom field and sets the PublicationDate for all news items to the value specified in their ArticleDate custom field.

    var newsAll = App.WorkWith()
                     .NewsItems()
                     .Where(nI => nI.Status == ContentLifecycleStatus.Live)
                     .ForEach(nI =>
                     {
                         var val = nI.GetValue("ArticleDate").ToString();
                         var ss = DateTime.Parse(val);
                         nI.PublicationDate = ss;
                     })
                     .SaveChanges();


    All the best,
    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
  3. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    09 May 2011
    Link to this post
    Hi,

    GetValue property doesn't show in the news item variable. Is there any reference's i need to add.

    Thanks,
    sathya
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 May 2011
    Link to this post
    Hi sathiyaseelan,

    Add using Telerik.Sitefinity.Model;

    Kind regards,
    Ivan Dimitrov
    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
  5. sathiyaseelan
    sathiyaseelan avatar
    82 posts
    Registered:
    26 Aug 2008
    09 May 2011
    Link to this post
    Hi,

    I am getting "Object reference error" on the line in the following code when I get the value for newsdate.

                var AllNews = 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;
                                 }).Get().ToList();

    I had added the custom field "NewsDate" in the news manager settings as well. Is there any thing else I need to do.
    to get the value.
    Thanks,
    sathya
  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    09 May 2011
    Link to this post
    Hi sathiyaseelan,

    Try using TryGetValue. The error you get means that the dynamic field is not found.

    Greetings,
    Ivan Dimitrov
    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
6 posts, 0 answered