[英]CAML “In” Operator Equivalent For SharePoint Services 3 (SharePoint 2007)
[英]CAML query to retrieve only published pages from SharePoint 2007?
我目前正在检索所有页面并过滤掉未在代码中发布的页面,检查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;
}
什么是等效的CAML查询,以便我不从数据库中提取不必要的项目?
以下是用于检查文档发布的CAML查询的示例。 我知道这是一个相当古老的问题,但希望这可能对下一个谷歌如何做到这一点的人有用:
<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>
在我的观点中,你的检查方式太多了。
您应该只检查“PublishingStartDate”<=今天和“PublishingExpirationDate”>今天
对于普通用户,您将找不到未发布/批准的页面。
对于有权查找这些页面的用户,您可能不希望仅仅因为当前版本未发布/批准而将其排除。 如果您只想要发布至少一个版本的页面,则可以添加“_UIVersion”> = 512的检查
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.