More in this section

Forums / General Discussions / get correct url for news items

get correct url for news items

4 posts, 0 answered
  1. NuToSitefinity
    NuToSitefinity avatar
    140 posts
    Registered:
    01 Sep 2010
    24 Feb 2011
    Link to this post
    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;
           }
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    25 Feb 2011
    Link to this post
    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
  3. Bruno Michels
    Bruno Michels avatar
    125 posts
    Registered:
    16 Apr 2010
    06 Apr 2011
    Link to this post
    I am getting a NullReferenceException on

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


    Why?
  4. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    06 Apr 2011
    Link to this post
    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

4 posts, 0 answered