[英]CAML query to retrieve only published pages from SharePoint 2007?
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: 我目前正在检索所有页面并过滤掉未在代码中发布的页面,检查DateTime.Now
是否小于此:
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? 什么是等效的CAML查询,以便我不从数据库中提取不必要的项目?
The following is an example of the CAML query for checking a document is published. 以下是用于检查文档发布的CAML查询的示例。 I'm aware this is a fairly old question but hopefully this might be of use to the next person who googles how to do this: 我知道这是一个相当古老的问题,但希望这可能对下一个谷歌如何做到这一点的人有用:
<Query>
<Where>
<And>
<Or>
<Leq>
<FieldRef Name='PublishingStartDate'/>
<Value Type='DateTime' IncludeTimeValue='TRUE'>
<Today/>
</Value>
</Leq>
<IsNull>
<FieldRef Name='PublishingStartDate'/>
</IsNull>
</Or>
<Or>
<Geq>
<FieldRef Name='PublishingExpirationDate'/>
<Value Type='DateTime' IncludeTimeValue='TRUE'>
<Today/>
</Value>
</Geq>
<IsNull>
<FieldRef Name='PublishingExpirationDate'/>
</IsNull>
</Or>
</And>
</Where>
</Query>
In my opion you're checking way too much. 在我的观点中,你的检查方式太多了。
You should only check "PublishingStartDate" <= Today and "PublishingExpirationDate" > Today 您应该只检查“PublishingStartDate”<=今天和“PublishingExpirationDate”>今天
For ordinary users you'll not find pages that isn't published/approved. 对于普通用户,您将找不到未发布/批准的页面。
For users with rights to find these pages you probably don't want to exclude them just because the current version isn't published/approved. 对于有权查找这些页面的用户,您可能不希望仅仅因为当前版本未发布/批准而将其排除。 If you only want pages where at least one version is published then you can add a check for "_UIVersion" >= 512 如果您只想要发布至少一个版本的页面,则可以添加“_UIVersion”> = 512的检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.