Frederik Vig – ASP.NET developer

Follow me

EPiServer filter – part 1

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

FilterForVisitor.Filter(news);

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:

Share:
  • Twitter
  • DotNetKicks
  • DZone
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Digg

9 Comments

  1. Steve Celius says:

    Nice! To the point!

    /Steve

  2. [...] you haven’t, be sure to check out EPiServer filter – part 1. In one of my project I had a bunch of categories and needed to filter a PageDataCollection to find [...]

  3. [...] #4 we filter out pages the user does not have access too. See EPiServer filter – part 1 for more [...]

  4. [...] more on EPiServer filtering see: EPiServer filter – part 1 and EPiServer filter – part 2: create your own filter. protected override void [...]

  5. How can I filter published/created pages which are having create date lying between a specified span of date.
    For e.g. getting Pages which are created between 1st February 2010 to 23rd February 2010

  6. Frederik Vig says:

    Hi SreeRaghavendra
    I would create my own filter. See my post: http://www.frederikvig.com/2009/06/episerver-filter-part-2/ for more information.

    Frederik

  7. But the property Criterias which we add into the propertycriteriacollection for FindPagesWithCriteria are all “AND” conditions within each property or they are “OR” ones.
    i mean to say suppose there are two properties for Pagename and PageCreated.So when the filter is executed all those pages satisfying both the criterias are executed or pages satisfying either of criterias are executed. If it is the former one then why is it that in SearchdataSource where the PropertyCriteriaControl (having multiple PropertyCriterias) have and “OR” condition within each other?

    Thanks for your reply.

  8. Frederik Vig says:

    You can specify this with the Required property on the criteria.

    Frederik

  9. Hi Fredrik,

    Thank you so much for clarifying my doubt.

    Regards,
    S.K. SreeRaghavendra

Leave a Reply

Spam Protection by WP-SpamFree

© Copyright Frederik Vig. Based on Fluid Blue theme