Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

FindPagesWithCriteria not returning only items between date range

Vote:
 

 

I am creating a page where the user can choose to view only pages published within a particular month, so I tried using the following code. But it always returns all of the pages. If I use just one of the PropertyCriteria, say dateCriteriaEnd, then this correctly returns only pages published before the end date. I could add a PropertyCriteria for selecting pages containing particular text; so FindPagesWithCriteria works with two criteria. Is this a bug FindPagesWithCriteriaor have I done missed something?

 

// -- Code start in EPiServer.UserControlBase

int month = 8;
int year = 2009;

DateTime minDate = new DateTime(year, month, 1, 0, 0, 1);
DateTime maxDate = new DateTime(year, month, 30, 23, 59, 59);

PropertyCriteriaCollection searchCriteria = new PropertyCriteriaCollection();

PropertyCriteria dateCriteriaEnd = new PropertyCriteria();
dateCriteriaEnd.Condition = EPiServer.Filters.CompareCondition.LessThan;
dateCriteriaEnd.Name = PAGE_DATE_PROPERTY; // PAGE_DATE_PROPERTY = "PageStartPublish";
dateCriteriaEnd.Type = PropertyDataType.Date;
dateCriteriaEnd.Value = maxDate.ToString();

searchCriteria.Add(dateCriteriaEnd);

PropertyCriteria dateCriteriaMin = new PropertyCriteria();
dateCriteriaMin.Condition = EPiServer.Filters.CompareCondition.GreaterThan;
dateCriteriaMin.Name = PAGE_DATE_PROPERTY;
dateCriteriaMin.Type = PropertyDataType.Date;
dateCriteriaMin.Value = minDate.ToString();

ltlMessage.Text += ", DateMin=" + minDate.ToString("dd/MMM/yyyy HH:mm:ss");
ltlMessage.Text += ", DateMax=" + maxDate.ToString("dd/MMM/yyyy HH:mm:ss");

searchCriteria.Add(dateCriteriaMin);

PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria(ListPageID(), searchCriteria);

// pgListing is a EPiServer:PageList control on the user control
pgListing.DataSource = pages;


pgListing.Paging = true;
pgListing.PagesPerPagingItem = 8;

pgListing.DataBind();

 

#32665
Sep 11, 2009 13:12
Vote:
 

I have just found the answer, the PropertyCriteria needs to have the Required property set to true for each criteria:

PropertyCriteria dateCriteriaMin = new PropertyCriteria();
dateCriteriaMin.Condition = EPiServer.Filters.CompareCondition.GreaterThan;
dateCriteriaMin.Name = PAGE_DATE_PROPERTY;
dateCriteriaMin.Type = PropertyDataType.Date;
dateCriteriaMin.Value = minDate.ToString();
dateCriteriaMin.Required = true; 

 

#32666
Sep 11, 2009 13:19
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.