get correct url for news items

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

get correct url for news items

All Replies

Posted by Community Admin on 24-Feb-2011 00:00

How can I get the correct url for the news items? I'm trying to load my datalist that I created and I'm able to get the news title, status, etc but not the correct url. The 'out of the box' news module has the URL as /year/month/date/newstitle, in my datalist I'm showing /appname/home/template/newstitle

what field do I need to show to get the correct URL for my news item?

here is my code, is this not the correct code?

public IQueryable<NewsItem> GetAllNews()
       
           NewsManager manager = NewsManager.GetManager();
           IQueryable<NewsItem> allNews = manager.GetNewsItems()
                   .Where(n => n.Status == ContentLifecycleStatus.Live);
                  
           return allNews;
       

Posted by Community Admin on 25-Feb-2011 00:00

Hi CsharpGuy,

You need to get the UrlData

var test = App.WorkWith().NewsItem().Get().Urls.Where(u => u.RedirectToDefault == false);

Note that the entire url is formatted based on the page on which you should have NewsView widget. The url that will be returned by the code above does not exist as site map node.

Best wishes,
Ivan Dimitrov
the Telerik team

Posted by Community Admin on 06-Apr-2011 00:00

I am getting a NullReferenceException on

App.WorkWith().NewsItem().Get()


Why?

Posted by Community Admin on 06-Apr-2011 00:00

Hello Bruno ,

Get a single new item in Master status

var test = App.WorkWith().NewsItems().Where(ni => ni.Status == ContentLifecycleStatus.Master).First().Get().Urls.Where(u => u.RedirectToDefault == false);

Best wishes,
Ivan Dimitrov
the Telerik team


This thread is closed