如何获取重复出现的SharePoint日历列表项

时间:2009-06-18 00:00:00

标签: sharepoint caml spquery

我在与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);
    }

3 个答案:

答案 0 :(得分:2)

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

oSb.Append("<Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
...
oSb.Append("</Query>");

答案 1 :(得分:1)

最好将ViewName绑定传递给您的自定义查询,如下所示

    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;
}

答案 2 :(得分:0)

你在使用什么列表视图?

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

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