如何获取重复的 SharePoint 日历列表项目
我在与 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不熟悉查询日历项目,但是我在使用 SPQuery.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:最好将 ViewName 绑定传递给您的自定义查询,如下所示
It's good idea to pass ViewName tie to your custom query as shown below
嘿,您使用什么列表视图?
由于您没有指定从中检索项目的视图,因此它会从默认视图中获取查询结果。
您的默认视图有可能不是日历视图吗?
因为我认为 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.