News control date issue

Posted by Community Admin on 03-Aug-2018 12:03

News control date issue

All Replies

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

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.?

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

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

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

Hi,

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

Thanks,
sathya

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

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

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

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

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

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

This thread is closed