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

发布于 2024-07-25 01:11:11 字数 2898 浏览 3 评论 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);
    }

Im running this query on the same server as the web application, so SPQuery.ExpandRecurrence should work. However, with the following I only get 3 items in the returned list collection vs. the 3 items and the re-occurrences, all of which fall within the current month.

I did verify with Stramit Caml Viewer that the query works, and returns the same 3 items.

Please tell me I'm missing something blatenly obvious?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

极度宠爱 2024-08-01 01:11:11

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

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

I'm not familiar with querying calendar items, however I've had problems using the <Query> tags for the SPQuery.Query property. Does it work correctly if you remove these two lines:

oSb.Append("<Query xmlns=\"http://schemas.microsoft.com/sharepoint/soap/\">");
...
oSb.Append("</Query>");
眸中客 2024-08-01 01:11:11

最好将 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;
}

It's good idea to pass ViewName tie to your custom query as shown below

    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;
}
怀里藏娇 2024-08-01 01:11:11

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

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

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

Hey what list view are you using?

Since you are not specifying the view from which you are retrieving the items, it is picking up the query results from the default view.

Any chance your default view is anything other than a calendar view?
Because i think the ExpandRecurrence work only for calendar views and not any other views.

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