0

I have a SharePoint calendar list which has some recurring events i wanted a report of about last two years. Following is the code that i have written

SPQuery qryBookings = new SPQuery();
                            qryBookings.ViewFields = "<FieldRef Name='Title'/>" +
                                                      "<FieldRef Name='LinkedBID'/>" +
                                                   "<FieldRef Name='Hosted_x0020_By'/>" +
                                                   "<FieldRef Name='Author'/>" +
                                                   "<FieldRef Name='Editor'/>" +
                                               "<FieldRef Name='ID'/>" +
                                               "<FieldRef Name='EventDate'/>" +
                                                "<FieldRef Name='Duration'/>" +
                                "<FieldRef Name='Room'/>" +
                                "<FieldRef Name='Place'/>" +
                                "<FieldRef Name='Linked_x0020_Id'/>" +
                                "<FieldRef Name='UID'/>" +
                                "<FieldRef Name='Is_x0020_Linked'/>" +
                            "<FieldRef Name='fRecurrence'/>" +
                                "<FieldRef Name='Internal_x0020_Meeting'/>" +
                            "<FieldRef Name='RecurrenceID' />" +
                             "<FieldRef Name='MasterSeriesItemID'/>" +
                            "<FieldRef Name='EventType'/>" +
                                "<FieldRef Name='Virtual_x0020_Room'/>" +
                            "<FieldRef Name='EndDate'/>" +
                            "<FieldRef Name='Changeit'/>";
                            qryBookings.Query = "<Where>" +
                                            "<DateRangesOverlap><FieldRef Name='EventDate' />" +//<And>
                                            "<FieldRef Name='EndDate' />" +
                                            "<FieldRef Name='RecurrenceID' />" +
                                            "<Value Type='DateTime'><Year/></Value></DateRangesOverlap></Where><GroupBy Collapse ='TRUE'><FieldRef Name='EventDate'></FieldRef></GroupBy>";//<Eq><FieldRef Name='ID' /><Value Type='Counter'>4</Value></Eq></And><Eq><FieldRef Name='Linked_x0020_Id' /><Value Type='Text'>96312753-ca76-466f-87d4-c0f2387c2390</Value></Eq></And>

                            qryBookings.ExpandRecurrence = true;
                            qryBookings.CalendarDate = DateTime.Now;


                            SPListItemCollection bk_collec = lstBookings.GetItems(qryBookings);

According to most of the blogs <Year/> returns all the events in the year in which the qryBookings.CalendarDate = DateTime.Now; falls.

Now today is 17th Sept 2014 and on testing i found that the results returned are from 17th Sept 2013 to 17th June 2015 which is different from what most of the blogs say. i.e. this

Can anyone explain me what exactly happens and also let me know if there is a way where i can request for events which are in the span of more than a year.

Thanks

0

My experience has found that doing calendar queries with recurrence expansion for a year are not dependable as SharePoint might throttle the results. I do not have specifics on why this happens.

I found the most dependable results by doing 1 month queries. So if you need to do 1 year - break it down into 12 months and for 2 years - 24 months.

See my answer here for more details and edge events you will want to take care of if you decide to do 1 month queries.

This was for SharePoint 2007 and 2010. I have not tested the dependability of year long queries against SharePoint 2013 [yet].

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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