EPiServer filter – part 1

Posted on May 28, 2009 by Frederik Vig in Code Snippet, EPiServer

Often we need to filter some of the pages in our PageDataCollection. Perhaps we wish to only show the pages that are published or that the user has access to. For this EPiServer has a few filter classes. Below you’ll find some examples. More information in the EPiServer SDK under the EPiServer.Filter namespace

Lets start by creating a PageDataCollection of the current pages children

PageDataCollection news = GetChildren(CurrentPage.PageLink);

Remember to add using EPiServer.Filters; to use the filter classes.

Remove pages that are not published

EPiServer 4

new FilterPublished().Filter(this, new FilterEventArgs(news));

EPiServer CMS 5 & 6

new FilterPublished(PagePublishedStatus.Published).Filter(news);

More information on the PagePublishedStatus enum in the SDK.

Filter by both published and read access

EPiServer CMS 5 & 6


Filter by access level

If the user does not at least have edit access, the page will get removed.

EpiServer CMS 5 & 6

// using EPiServer.Security;
new FilterAccess(AccessLevel.Edit).Filter(news);

More information on the AccessLevel enum in the SDK.

Sort the collection after a property value

EPiServer CMS 5 & 6

// Default is Ascending
new FilterPropertySort("PageName").Filter(news);
new FilterPropertySort("PageName", FilterSortDirection.Descending).Filter(news);

Filter out pages where a property has no value

EPiServer CMS 5 & 6

new FilterRemoveNullValues("MainBody").Filter(news);

Filter by a custom property

EPiServer CMS 5 & 6

new FilterCompareTo("PageVisibleInMenu", "true").Filter(news);

In the EPiServer SDK there is a nice overview of the built in EPiServer properties.

Related Posts: