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

Forums / Developing with Sitefinity / Trying to pull all visible pages results in: Error: Object reference not set to an instance of an object

Trying to pull all visible pages results in: Error: Object reference not set to an instance of an object

3 posts, 0 answered
  1. Jason
    Jason avatar
    0 posts
    Registered:
    28 Nov 2016
    14 Feb
    Link to this post

    Please tell me if there is something wrong with this line of code:

    var pages = App.WorkWith().Pages().ThatArePublished().Where(p => p.GetPageData().Visible).Get().ToList();

    I am trying to get all visible pages, because I believe the .ThatArePublished() method in my version of Sitefinity doesn't work correctly, as it is pulling in pages that are not published. This is a work around I discovered on these forums, but am having trouble implementing it. 

    Am I doing something wrong here? All my function does is return the page variable, and parses it from there. I have it tracked down to this very line of code. Any help would be greatly appreciated! Thank you.

  2. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    15 Feb
    Link to this post

    Give up on the fluent api and just use the mangers.  Fluent just wraps them anyway and leaves out too many things.

     

    Filter on staus live and visible true

  3. Victor Leontyev
    Victor Leontyev avatar
    65 posts
    Registered:
    01 Jul 2014
    15 Feb
    Link to this post

    Steve is absolutely right.

    But if u still want to use fluent, you can try this code. It's taking published, filtering by language and not deleted:

    var newCulture = new CultureInfo("en");
    var pagesFl = App.WorkWith().Pages()
             .LocatedIn(PageLocation.Frontend)
             .ThatArePublished()
             .ThatAreForLanguage(newCulture)
             .Get()
             .Where(p => p.IsDeleted == false)
             .OrderByDescending(x => x.LastModified).ToList();

     

3 posts, 0 answered