0

我正在使用 CAML 查询来检索一系列日期中的事件。目前,即使日期范围内有事件,它也不会检索任何内容

我的 CAML 查询有问题吗?当我拿走查询行时它可以检索所有事件

这是我的代码:

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

1 回答 1

0

Your query contains elements value and leq with incorrect casing. The correct casing is Value and Leq (see this). You also use incorrect date format in the query. You must format the date to string using the SPUtility.CreateISO8601DateTimeFromSystemDateTime method (see this). Also use FALSE/TRUE instead of false/true in IncludeTimeValue attribute.

于 2013-10-02T10:24:13.057 回答