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
- Categories: .NET, ASP.NET, Software Development, EPiServer
- Additional keywords: FindPagesWithCriteria EPiServer, Search, Permissions, Published, FindPagesWithCriteria EPiServer Publishing Dates
- Technorati Tags: software development, EPiServer, .NET, ASP.NET, FindPagesWithCriteria, search, publishing, security