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


Bookmark with :
Digg It! DZone StumbleUpon Technorati Reddit Del.icio.us Newsvine Furl Blinklist
posted @ Friday, January 18, 2008 3:53 PM | in EPiServer ASP.NET Software Development

Comments

Gravatar
# re: EPiServer: FindPagesWithCriteria, Multiple Criteria and Boolean Property Tests
Posted by Jakob
on 4/17/2008 4:31 PM
Thank you!!

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 3 and 2 and type the answer here: