2013-10-01 79 views
0

我正在使用CAML查詢檢索日期範圍內的事件。 目前,它沒有檢索到任何事件,儘管日期範圍內有事件CAML查詢在SharePoint日曆中檢索日期範圍

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

回答

0

查詢包含內容valueleq不正確的外殼。正確的外殼是ValueLeq(請參閱this)。您還在查詢中使用不正確的日期格式。您必須使用SPUtility.CreateISO8601DateTimeFromSystemDateTime方法將日期格式化爲字符串(請參閱this)。在IncludeTimeValue屬性中也使用FALSE/TRUE而不是false/true