I am currently retrieving all pages and filtering out ones that are not published in the code, checking whether DateTime.Now
is smaller than this:
static readonly DateTime IMMEDIATE_PUBLISH = new DateTime(1900, 1, 1);
public static DateTime PublicationDate(this SPListItem item)
{
// get start publish date
PublishingPage page = item.Publishing();
if (page != null)
{
bool isPublished = (page.ListItem.File != null)
? (page.ListItem.File.Level == SPFileLevel.Published)
: true;
bool isApproved = (page.ListItem.ModerationInformation != null)
? (page.ListItem.ModerationInformation.Status == SPModerationStatusType.Approved)
: true;
if (isPublished && isApproved && (DateTime.Now < page.EndDate))
{
return page.StartDate == IMMEDIATE_PUBLISH ? page.CreatedDate : page.StartDate;
}
return DateTime.MaxValue;
}
// not a scheduled item. treat as published
return DateTime.MinValue;
}
What would be the equivalent CAML query, so that I SharePoint doesn't pull unnecessary items from the database?