0

我在与 Web 应用程序相同的服务器上运行此查询,因此 SPQuery.ExpandRecurrence 应该可以工作。但是,使用以下内容,我在返回的列表集合中只得到 3 个项目,而这 3 个项目和重复出现,所有这些都属于当月。

我确实使用 Stramit Caml Viewer 验证了查询是否有效,并返回了相同的 3 个项目。

请告诉我我遗漏了一些明显的东西吗?

    static SPListItemCollection GetSourceColl(SPList list)
    {
        SPQuery query = new SPQuery();
        query.ExpandRecurrence = true;
        query.CalendarDate = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 1);

        System.Text.StringBuilder oSb = new System.Text.StringBuilder();

        oSb.Append("     <Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
        oSb.Append("         <Where>");
        oSb.Append("              <And>");
        oSb.Append("                   <DateRangesOverlap>");
        oSb.Append("                        <FieldRef Name=\"EventDate\" />");
        oSb.Append("                        <FieldRef Name=\"EndDate\" />");
        oSb.Append("                        <FieldRef Name=\"RecurrenceID\" />");
        oSb.Append("                        <Value Type=\"DateTime\">");
        oSb.Append("                             <Month />");
        oSb.Append("                        </Value>");
        oSb.Append("                   </DateRangesOverlap>");
        oSb.Append("                   <And>");
        oSb.Append("                        <And>");
        oSb.Append("                             <Eq>");
        oSb.Append("                                  <FieldRef Name=\"Status\" />");
        oSb.Append("                                  <Value Type=\"Text\">Finalized</Value>");
        oSb.Append("                             </Eq>");
        oSb.Append("                             <Leq>");
        oSb.Append("                                  <FieldRef Name=\"DistributionStartDate\" />");
        oSb.Append("                                  <Value Type=\"DateTime\">");
        oSb.Append("                                       <Today />");
        oSb.Append("                                  </Value>");
        oSb.Append("                             </Leq>");
        oSb.Append("                        </And>");
        oSb.Append("                        <Neq>");
        oSb.Append("                             <FieldRef Name=\"Distribution\" />");
        oSb.Append("                             <Value Type=\"Text\">Intranet</Value>");
        oSb.Append("                        </Neq>");
        oSb.Append("                   </And>");
        oSb.Append("              </And>");
        oSb.Append("         </Where>");
        oSb.Append("    </Query>");
        query.Query = oSb.ToString();

        return list.GetItems(query);
    }
4

3 回答 3

2

我不熟悉查询日历项目,但是我在使用<Query>SPQuery.Query 属性的标签时遇到了问题。如果删除这两行,它是否可以正常工作:

oSb.Append("<Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
...
oSb.Append("</Query>");
于 2009-06-18T14:11:53.693 回答
1

将 ViewName tie 传递给您的自定义查询是个好主意,如下所示

    private SPListItemCollection GetSourceColl(SPList list, string viewName)
{
    SPQuery query = new SPQuery();
    query.ExpandRecurrence = true;
    query.CalendarDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
    System.Text.StringBuilder oSb = new System.Text.StringBuilder();
    oSb.Append("<Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
    oSb.Append("         <Where>"); oSb.Append("              <And>");
    oSb.Append("                   <DateRangesOverlap>");
    oSb.Append("                        <FieldRef Name=\"EventDate\" />");
    oSb.Append("                        <FieldRef Name=\"EndDate\" />");
    oSb.Append("                        <FieldRef Name=\"RecurrenceID\" />");
    oSb.Append("                        <Value Type=\"DateTime\">");
    oSb.Append("                             <Month />");
    oSb.Append("                        </Value>");
    oSb.Append("                   </DateRangesOverlap>");
    oSb.Append("                   <And>");
    oSb.Append("                        <And>");
    oSb.Append("                             <Eq>");
    oSb.Append("                                  <FieldRef Name=\"Status\" />");
    oSb.Append("                                  <Value Type=\"Text\">Finalized</Value>");
    oSb.Append("                             </Eq>");
    oSb.Append("                             <Leq>");
    oSb.Append("                                  <FieldRef Name=\"DistributionStartDate\" />");
    oSb.Append("                                  <Value Type=\"DateTime\">");
    oSb.Append("                                       <Today />");
    oSb.Append("                                  </Value>");
    oSb.Append("                             </Leq>");
    oSb.Append("                        </And>");
    oSb.Append("                        <Neq>");
    oSb.Append("                             <FieldRef Name=\"Distribution\" />");
    oSb.Append("                             <Value Type=\"Text\">Intranet</Value>");
    oSb.Append("                        </Neq>");
    oSb.Append("                   </And>");
    oSb.Append("              </And>");
    oSb.Append("         </Where>");
    oSb.Append("    </Query>");
    query.Query = oSb.ToString();
    SPListItemCollection itemColl = null;
    if (string.IsNullOrEmpty(viewName))
    {
        itemColl = list.GetItems(query);
    }
    else
    {
        itemColl =  list.GetItems(query, viewName);
    }
    return itemColl;
}
于 2012-03-13T02:58:13.650 回答
0

嘿,您使用的是什么列表视图?

由于您没有指定从中检索项目的视图,因此它会从默认视图中获取查询结果。

您的默认视图是否有可能不是日历视图?因为我认为 ExpandRecurrence 仅适用于日历视图,而不适用于任何其他视图。

于 2009-06-18T07:14:26.547 回答