My C# application runs outside SharePoint, so I'm using CSOM with a Caml query. I want to find all calendar events, single and recurring, that are scheduled for a single day. I'm getting ALL recurring calendar events that overlap my selected day even if they do not have any scheduled events on the day in question. Single events are correctly filtered and returned. How do I filter the recurring events to only those that fire on the given date? Is this any easier with a Task list rather than a Calendar list?
var today = DateTime.UtcNow.ToString(@"yyyy-MM-ddT12:00:00Z");
var query = new CamlQuery {
ViewXml = @"<View>
<ViewFields>
<FieldRef Name='ID' />
<FieldRef Name='Title' />
<FieldRef Name='EventDate' />
<FieldRef Name='EndDate' />
<FieldRef Name='Description' />
<FieldRef Name='Category' />
<FieldRef Name='fRecurrence' />
<FieldRef Name='RecurrenceData' />
<FieldRef Name='fAllDayEvent' />
</ViewFields>
<Query>
<Where>
<DateRangesOverlap>
<FieldRef Name='EventDate'></FieldRef>
<FieldRef Name='EndDate'></FieldRef>
<FieldRef Name='RecurrenceID'></FieldRef>
<Value Type='DateTime'><Today/></Value>
</DateRangesOverlap>
</Where>
<OrderBy><FieldRef Name='EventDate' /></OrderBy>
</Query>
<QueryOptions>
<CalendarDate>"+ today + @"</CalendarDate>
<RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>
<ExpandRecurrence>TRUE</ExpandRecurrence>
</QueryOptions>
</View>"
};