CAML 查询仅检索 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 查询是什么,以便我的 SharePoint 不会从数据库中提取不需要的项目?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在我看来,你检查得太多了。
您应该只检查“PublishingStartDate”<= 今天和“PublishingExpirationDate”>今天,
对于普通用户,您将找不到未发布/批准的页面。
对于有权查找这些页面的用户,您可能不想仅仅因为当前版本尚未发布/批准而排除它们。如果您只想要至少发布一个版本的页面,那么您可以添加对“_UIVersion”>= 512 的检查
In my opion you're checking way too much.
You should only check "PublishingStartDate" <= Today and "PublishingExpirationDate" > Today
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
以下是用于检查文档是否已发布的 CAML 查询的示例。我知道这是一个相当老的问题,但希望这可能对下一个通过谷歌搜索如何做到这一点的人有用:
The following is an example of the CAML query for checking a document is published. 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: