SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm facing a problem building a caml query for the calendar list. Here is my caml query

                SPQuery query = new SPQuery();

                StringBuilder sb = new StringBuilder();
                sb.Append("<FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' />");
                sb.Append("<Value Type='DateTime'><Month /></Value>");
               sb.Append("<Geq><FieldRef Name='EventDate'/><Value Type='DateTime'><Today Offset='-1'/></Value></Geq>");

                sb.Append("<OrderBy><FieldRef Name='EventDate' /></OrderBy>");

                query.RowLimit = numberOfUpcomingEvents;
                query.Query = sb.ToString();
                query.ExpandRecurrence = true;
                query.CalendarDate = DateTime.Now;

The problem is that it won't work properly if there is an recurring event that starts before current date but the next recurrence is on current date after. How to retrieve recurrence events as single events?

Anyone has suggestions?

share|improve this question

try this

using (SPSite spsite = SPContext.Current.Site)
                using (SPWeb web = spsite.OpenWeb())
                    SPQuery query = new SPQuery();
                    SPList list = web.Lists["CalendarList"];
                    query. ExpandRecurrence = true;
                   // query.RowLimit = 20;
                    query.Query = @"<Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><Now /></Value></DateRangesOverlap></Where><OrderBy><FieldRef Name='EventDate' Ascending='True' /></OrderBy>";
                    query.ViewFields = "<FieldRef Name='Title' LinkToItem='TRUE'/><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='fRecurrence' /><FieldRef Name='RecurrenceData' /><FieldRef Name='Location' />";                         
                    SPListItemCollection listItems;
                    listItems = list.GetItems(query);
                    foreach (SPListItem item in listItems)
                        if (item["fRecurrence"].ToString() == "True")  
share|improve this answer

Try adding in an additional option <QueryOptions><RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion><ExpandRecurrence>TRUE</ExpandRecurrence></QueryOptions>

share|improve this answer
It's the same result :( – MIlena May 6 '13 at 8:32
up vote 0 down vote accepted

Just got the solution.

I read it on another thread and the summary is:

  1. Create two new Columns called Start Filter and End Filter. Make these columns Calculated Columns with formulas of [Start Time] and [End Time] respectively. The columns should be of the Date and Time\Date and Time type and should not be displayed on the Default View.

  2. Click Advanced Settings and choose Yes to the question "Allow management of Content Types" in the Content Types section. Click OK.

My query to get uppcoming events with recurring events is:

    <FieldRef Name='EventDate' />
          <FieldRef Name='Start_x0020_Filter' />
          <Value Type='DateTime'>
            <Today Offset='-1' />
          <FieldRef Name='End_x0020_Filter' />
          <Value Type='DateTime'>
            <Today Offset='-1' />
        <FieldRef Name='Start_x0020_Filter' />
        <Value Type='DateTime'>
          <Today Offset='-1' />

Now I can filter all upcoming events

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.