News control date issue
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.?
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();
Hi,
GetValue property doesn't show in the news item variable. Is there any reference's i need to add.
Thanks,
sathya
Hi sathiyaseelan,
Add using Telerik.Sitefinity.Model;
Kind regards,
Ivan Dimitrov
the Telerik team
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
Hi sathiyaseelan,
Try using TryGetValue. The error you get means that the dynamic field is not found.
Greetings,
Ivan Dimitrov
the Telerik team