EPiServer FindPagesWithCriteria and FindAllPagesWithCriteria
Posted on October 21, 2009 by Frederik Vig in EPiServerI 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
- FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias)
- FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch)
- FindPagesWithCriteria(PageReference pageLink, PropertyCriteriaCollection criterias, string languageBranch, ILanguageSelector selector)
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")); |
- All matched pages that the current user has read access to and that are published.
- All matched pages that the current user has read access to, that are published and that have an English version
- 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.
- 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
- PropertySearch Class
- Search for EPiServer pages based on properties
- FindPagesWithCriteria and Performance
- A quick comparsion between FindPagesWithCriteria and a recursive GetChildren
Eric Herlitz says:
Post Author October 18, 2012 at 17:27I think you need to rephrase this a bit
“FindPagesWithCriteria will filter out pages the requester does not have access to and that are not published, while FindAllPagesWithCriteria will return all matched pages.”
The FindPagesWithCriteria will filter out pages the requester has read access for and that are published.
Solid work otherwise, thanks.