CAML 查询仅检索 SharePoint 2007 中已发布的页面?

发布于 2024-09-08 13:52:02 字数 1039 浏览 2 评论 0原文

我目前正在检索所有页面并过滤掉代码中未发布的页面,检查 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迟月 2024-09-15 13:52:02

在我看来,你检查得太多了。

您应该只检查“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

人间不值得 2024-09-15 13:52:02

以下是用于检查文档是否已发布的 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>

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:

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文