EPiServer filter – part 1
Posted on May 28, 2009 by Frederik Vig in Code Snippet, EPiServerOften 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:
Frederik Vig
Post Author
I'm a partner and ASP.NET developer for the Norwegian web agency Geta. I mainly write about things I work with, which are: .NET and web technologies
Other posts by Frederik Vig →
Steve Celius says:
Post Author May 29, 2009 at 20:21Nice! To the point!
/Steve
SreeRaghavendra says:
Post Author February 23, 2010 at 09:20How 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
Frederik Vig says:
Post Author February 23, 2010 at 09:29Hi SreeRaghavendra
I would create my own filter. See my post: http://www.frederikvig.com/2009/06/episerver-filter-part-2/ for more information.
Frederik
SreeRaghavendra says:
Post Author February 23, 2010 at 14:53But 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.
Frederik Vig says:
Post Author February 23, 2010 at 19:06You can specify this with the Required property on the criteria.
Frederik
SreeRaghavendra says:
Post Author February 24, 2010 at 12:14Hi Fredrik,
Thank you so much for clarifying my doubt.
Regards,
S.K. SreeRaghavendra