2010-07-02 78 views
1

我目前检索所有页面和过滤掉未发布代码的,检查DateTime.Now是否比这更小:CAML查询只检索SharePoint 2007发布的页面?

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不从数据库中拉出不必要的项目?

+1

根据此示例(http://www.stum.de/2008/03/13/caml-queries /),无论答案如何,这将是一个可怕的亵渎,并提醒为什么Sharepoint是恶魔的化身。 – Juliet 2010-07-02 07:12:23

+0

CAML.Net http://camldotnet.codeplex.com/有所帮助。 – skolima 2010-07-02 10:32:38

回答

2

在我的眼中,你检查的方式太多了。

后,再选中“PublishingStartDate” < =今天和“PublishingExpirationDate”>今天

对于普通用户来说,你会找不到未发布/批准页面。
对于有权查找这些网页的用户,您可能不希望仅因为当前版本未发布/核准而将其排除。如果您只想要至少发布一个版本的页面,那么您可以添加“_UIVersion”> = 512的检查

+0

问题是我试图缓存结果,并且最初的查询正在以完整的权限运行。我正在考虑改变我的缓存现在的工作方式。 – skolima 2010-07-02 12:12:20

+0

但是,如果您使用您在问题中指定的条件运行,那么即使旧版本已发布/批准,也会排除新版本正在进行的页面 – 2010-07-02 12:38:27

2

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