EPiServer: FindPagesWithCriteria and Publishing Dates

by Stephen Horsfield 3. January 2008 15:18

Overview

EPiServer does not exclude pages outside of publishing schedules when retrieved using the FindPagesWithCriteria method.

UPDATE

I've found the following article on the EPiServer website:  How Do I Search for Unpublished Pages.  The reverse logic should be applied, but it has the advantage of performing the filter at the data layer.  It involves adding two property criteria, one for PageStartPublish and one for PageStopPublish.

Don't be fooled by the EPiServer.Filters namespace, the FilterPublished class doesn't help!

Since that page is only visible to EPiServer site members, here's an example:

PropertyCriteriaCollection criterias =
  new PropertyCriteriaCollection();

startPublishCriteria.Condition = CompareCondition.LessThan;
startPublishCriteria.Name = "PageStartPublish";
startPublishCriteria.Value = DateTime.Now.ToString();
startPublishCriteria.Type = PropertyDataType.Date;
criterias.Add(startPublishCriteria);

PropertyCriteria stopPublishCriteria = new PropertyCriteria();
stopPublishCriteria.Condition = CompareCondition.GreaterThan;
stopPublishCriteria.Name = "PageStopPublish";
stopPublishCriteria.Value = DateTime.Now.ToString();
stopPublishCriteria.Type = PropertyDataType.Date;
criterias.Add(stopPublishCriteria);

PageDataCollection pages =
  Global.EPDataFactory.FindPagesWithCriteria(
  Global.EPConfig.StartPage,
  criterias);

Workaround

Once matching pages have been retrieved using FindPagesWithCriteria, apply a futher filter on the basis of the Page class's CheckPublishedStatus method.

Example

PageDataCollection pages = DataFactory.Instance.FindPagesWithCriteria(
    parent, col, AccessLevel.Read);
pages.Sort(new PageDataListComparer(SortType.DisplayDate,
    SortDirection.Descending));
 
System.Collections.Generic.List<PageData> removeList =
    new System.Collections.Generic.List<PageData>();
 
foreach (PageData p in pages)
{
if (p.CheckPublishedStatus(PagePublishedStatus.Published)) continue;
removeList.Add(p);
}
foreach (PageData pr in removeList) pages.Remove(pr);
 
return pages;

Versions

  • Microsoft .NET Framework v3.0
  • EPiServer 5
  • Windows Server 2003

Metadata

Tags:

ASP.NET | Software Development | EPiServer

Comments

8/25/2008 5:45:59 AM #

Hi Stephen, You are doing too much (coding) to get this. Simply add one more criteria as following:   PropertyCriteria pubCriteria = new PropertyCriteria();
pubCriteria.Condition =
   EPiServer.Filters.CompareCondition.Equal;
pubCriteria.Name = "PagePendingPublish";
pubCriteria.Type = PropertyDataType.Boolean;
pubCriteria.Value = false.ToString();


And one more correction in your given code. You need to use "stopPublishCriteria.Required = true;".

Hope you get this

Anadi

Anadi |

8/29/2008 8:27:59 AM #

I didn't use the required criteria as in many cases the stop publishing date was not present.

I haven't tried your code, but if it works then great.  The biggest problem I've had with EPiServer searching is combining of criteria as the logic is very basic.

Thanks for your feedback.

Stephen Horsfield |

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