EPiServer FindPagesWithCriteria and FindAllPagesWithCriteria

Posted on October 21, 2009 by Frederik Vig in EPiServer

I didn’t know about the FindAllPagesWithCriteria method until today. There is a subtle, but very important difference between the two. FindPagesWithCriteria will filter out pages the requester does not have access to and that are not published, while FindAllPagesWithCriteria will return all matched pages.

FindPagesWithCriteria

FindAllPagesWithCriteria

Example

For an introduction take a look at Ted Nyberg’s post Search for EPiServer pages based on properties.

Lets find all pages that are in the category News.

var criterias = new PropertyCriteriaCollection();
 
var category = new PropertyCriteria();
category.Condition = CompareCondition.Equal;
category.Value = "News";
category.Type = PropertyDataType.Category;
category.Required = true;
category.Name = "PageCategory";
 
criterias.Add(category);
// #1
var pages1 = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criterias);
 
// #2
var pages2 = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criterias, "en");
 
// #3
var pages3 = DataFactory.Instance.FindPagesWithCriteria(PageReference.StartPage, criterias, "no", new LanguageSelector("en"));
 
// #4
var pages4 = DataFactory.Instance.FindAllPagesWithCriteria(PageReference.StartPage, criterias, "no", new LanguageSelector("en"));
  1. All matched pages that the current user has read access to and that are published.
  2. All matched pages that the current user has read access to, that are published and that have an English version
  3. All matched pages that the current user has read access to, that are published, that have a Norwegian version and an English version. Note that the English version is the active one on the returned PageData objects.
  4. All matched pages, regardless of access rights, that have a Norwegian version and an English version. English is active.

Also remember that in EPiServer CMS 5 the GetChildren method got changed to return all pages, regardless of published status and access level.

Other resources

Related Posts: