简体   繁体   English

共享日历中的CAML查询检索日期范围

[英]CAML query retrieving date range in a sharepoint calendar

I am using CAML query to retrieve events in a range of dates. 我正在使用CAML查询来检索日期范围内的事件。 Currently, it retrieves nothing eventhough there are events in the range of dates 目前,即使有日期范围内的事件,它也无法检索到任何内容

Is there something wrong with my CAML Query? 我的CAML查询有问题吗? It can retrieve all events when i take away the query line 当我拿走查询行时,它可以检索所有事件

Here is my code: 这是我的代码:

DateTime todayDate = DateTime.Now.Date; 

DateTime tomorrowDate = todayDate.AddDays(1);
tomorrowDate = tomorrowDate.AddSeconds(-1);

query.Query = "<Query><Where><And><Geq><FieldRef Name=\"StartTime\" /><value IncludeTimeValue=\"true\" type=\"DateTime\">" + todayDate + "</value></Geq><leq><FieldRef Name=\"EndDate\"/><Value IncludeTimeValue=\"true\" Type=\"DateTime\">" + tomorrowDate + "</value></leq></And></Where><Query>";
query.ExpandRecurrence = true; 

query.ViewFields = @"<FieldRef Name='Title' /><FieldRef Name='EventDate' /><FieldRef Name='EndDate' />";

SPListItemCollection items = list.GetItems(query);

foreach (SPListItem listItem in items)
{
    retrievedData.Add(listItem["Title"].ToString());
    retrievedData.Add(listItem["EventDate"].ToString());
    retrievedData.Add(listItem["EndDate"].ToString());
}

Your query contains elements value and leq with incorrect casing. 您的查询中包含的元素valueleq不正确的外壳。 The correct casing is Value and Leq (see this ). 正确的大小写为ValueLeq (请参阅 )。 You also use incorrect date format in the query. 您还在查询中使用不正确的日期格式。 You must format the date to string using the SPUtility.CreateISO8601DateTimeFromSystemDateTime method (see this ). 您必须使用格式化的日期字符串SPUtility.CreateISO8601DateTimeFromSystemDateTime方法(见 )。 Also use FALSE/TRUE instead of false/true in IncludeTimeValue attribute. 还要在IncludeTimeValue属性中使用FALSE/TRUE而不是false/true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM