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


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

Comments

Gravatar
# re: EPiServer: FindPagesWithCriteria and Publishing Dates
Posted by Anadi
on 8/25/2008 6:45 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
Gravatar
# re: EPiServer: FindPagesWithCriteria and Publishing Dates
on 8/29/2008 9:27 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.

Post Comment

Title *
Name *
Email
Url
Comment *  


Please add 7 and 1 and type the answer here: