Also as a side note, is there any way to move away from FindAllPagesWithCriteria and use something like ContentRepository.GetChildren? However, GetChildren isn't recursive and only grabs the direct children, can I use this or similar to recursively find/filter pages in the heirarchy?
Hi,
As the name implies, 'FindAllPagesWithCriteria', it searches only for pages and thereby only supports PageReference.
You can do your own method that loops through all pages and which also takes a predicate. This works in general faster for small content structures.
If you rely heavily on searches like these I would recommend EPiServer Find.
Regarding the question on moving away from FindALlPAgesWithCriteria and using the ContentRepository instead there is the GetDecendents method that will retreive the entire tree below the selected reference
var loader = ServiceLocator.Current.GetInstance<IContentLoader>(); // all pages as ContentReference var allPages = loader.GetDescendents(ContentReference.StartPage); // all pages as PageData var allPageData = allPages.Select(x => loader.Get<PageData>(x)); // filtered pageDataColleciton var pageDataCollection = new PageDataCollection(allPageData).FilterForVisitor();
If you have a lot of pages you might want to consider the performance implications of loading them all at once as well. Prime target for logging execution time on this one and cache the result if needed.
... and to add what Daniel just wrote. Do not cache the PageData objects, but rather the PageReference objects.
...or cache the actual result you are constructing using the PageDatas. If it's a sitemap then cache the created links instead to save some memory. PageDatas can be pretty big objects x 1000s...
And make sure you don't have any authorization issues...That some pages shouldn't be displayed for certain people. Then only cache the result for anonymous users and fetch fresh for the others...
Hello,
I'm trying to use FindAllPagesWithCriteria like so:
However, when reaching this code, an exception is thrown: "The Type set on the criteria is not supported: 11"
I need to use contentreference as the type because the property type im searching for is a content reference
Any ideas?