Trying to pull all visible pages results in: Error: Object r

Posted by Community Admin on 04-Aug-2018 21:08

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

All Replies

Posted by Community Admin on 14-Feb-2017 00:00

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.

Posted by Community Admin on 15-Feb-2017 00:00

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

Posted by Community Admin on 15-Feb-2017 00:00

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();

 

This thread is closed