EPiServer: FindPagesWithCriteria, Multiple Criteria and Boolean Property Tests

by Stephen Horsfield 18. January 2008 15:53

Overview

This should be easy, but easy it is not.  I'm using an EPiServer 4.6 site for this one, so things might've improved in more recent versions, but this caused me a lot of trial and error.  I hope this post saves you the hassle.

Context

I've got a Selected/Unselected property set on a Page Type, and I want to search for pages with this property checked.  I also want to take account of publishing dates and I've got another date property to check too.

The EPiServer Selected/Unselected property type returns True when selected and Null when it is not.  This causes some problems because boolean logic is more complicated when Null values are involved.  This is because Null represents "I don't know".  If you ask, "Is A equal to B?" and A or B is Null, then the answer is Null... always!

The other problem is that I can only do certain expressions in the query.  I can say that some criteria are optional (union set) and some properties are required (intersection set).  I cannot reduce or expand a single clause and this limits what is allowed.

My solution

  1. I need to find pages with a date property less than the current date.  I'll call this property RequiredBefore
  2. I need to find pages with a boolean property that is set.  I'll call this property Flag
  3. I need to find pages that are currently published and accessible to the current user

Here's my code:

PageDataCollection col = new PageDataCollection();
PropertyCriteriaCollection propcol = new PropertyCriteriaCollection();
PropertyCriteria criteria = new PropertyCriteria();
criteria.Type = PropertyDataType.Date;
criteria.Name = "RequiredBefore";
criteria.Value = DateTime.Now.ToString();
criteria.Condition = EPiServer.Filters.CompareCondition.GreaterThan;
criteria.Required = true;
propcol.Add(criteria);

criteria = new PropertyCriteria();
criteria.Type = PropertyDataType.Boolean;
criteria.Name = "VisibleInSummary";
criteria.IsNull = false;
criteria.Value = true.ToString();
criteria.Condition = EPiServer.Filters.CompareCondition.Equal;
criteria.Required = true;
propcol.Add(criteria);

PageDataCollection tempcol = new PageDataCollection();
tempcol = Global.EPDataFactory.FindPagesWithCriteria(CurrentPageLink, propcol, EPiServer.Security.AccessLevel.Read);

// Check pages are published
foreach (PageData p in tempcol)
{
  if (p.Status == VersionStatus.Published)
    col.Add(p);
}
tempcol.Clear();

I'm checking for publishing dates after retrieving the pages which is inefficient.  I'm doing this because it is otherwise difficult to handle for the possibility of publishing dates being null, and this way I let EPiServer decide how to check for whether a page is considered published.

Versions

Metadata

Tags:

ASP.NET | EPiServer | Software Development

Comments

4/17/2008 3:31:14 PM #

Thank you!!

Jakob |

Powered by BlogEngine.NET 1.5.0.7
Theme by Interakting

Interakting

A full service digital agency offering online strategy, design and usability, systems integration and online marketing services that deliver real business benefits and ensure your online objectives are met.

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar