简体   繁体   中英

All events from Sharepoint calendar using webservice

I'm trying to get all list item in a calendar scheduled within 30 day of a given date.

            ndQueryOptions.InnerXml = "<ExpandRecurrence>TRUE</ExpandRecurrence>";
            ndQueryOptions.InnerXml += "<CalendarDate>" + calendarDate + "</CalendarDate>";
            ndQueryOptions.InnerXml += "<ViewAttributes Scope=\"RecursiveAll\" />";

            ndQuery.InnerXml = @"<Where><DateRangesOverlap><FieldRef Name=""EventDate"" /><FieldRef Name=""EndDate"" /><FieldRef Name=""RecurrenceID"" /><Value Type=""DateTime""><Now /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name=""EventDate"" /></OrderBy>";

Then I massage the data to get the data within the date range.

It seems to work if the given date is within a particular range. For example, I have an event for every Wednesday and Friday. if now is 6/5/2013, it returns data from now till 9/13/2013. Any query (for the given date) other than those two days (an earlier date like 4/5/2013 or a later date like 10/1/2014) returns no events between the date range.

Update: I changed the <Value Type=""DateTime""><Year /></Value> from <Now /> , result is better that it does return some historical data, but not to previous year, nor to next year.

Update: I followed Douglas's suggestion, it missed the DateRangesOverlap part, so it only returns one node for the recurrent event instead of unfolded them. So I don't think it works.

Update: I found an article explaining the value type for the DateRangesOverlap. Here confirms that <Year /> only returns data from today and does not work with calendar date (the start date I wanted it to be). According to that article, <Month /> is more reliable. So I can't do a date range search (at least not within a single web service call). I will use <Month /> instead.

You can have a try the following query string:

<Where><And><Leq><FieldRef Name='EventDate' /><Value Type='DateTime'>...</Value></Leq><Geq><FieldRef Name='EndDate' /><Value Type='DateTime'>...</Value></Geq></And></Where>

and specify the value of start date and end date with format like this 2013-06-01T00:00:00 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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