1

I want to fetch all the items on a particular day. Programmatically the entry is added as recurring event, Now i need to fetch all the instances of recurring event, on each day as per the date selected by the user.

E.g: I have made 3 recurring entries on 12thSept and which ends on 21stSept with all three having different TIME and a seperate ROOM NAME Calendar

I want to fetch all the items on 12th,13th,14th and so on till 21st as per the date selected.

The following is the code i am working with to fetch all the entries on a selected day, bt the issue i am having here is, The query returns items only if i select date as 12thSept and for all other dates i.e from 13th to 21st the query does not return any result.

    SPQuery oQueryBookings = new SPQuery();

                            string strQuery = "";
                            oQueryBookings.ExpandRecurrence = true;
                            //oQueryBookings.Query = strQuery;
                            oQueryBookings.CalendarDate = date.Date;
                            SPListItemCollection oCollBookings = null;
                            strQuery = "<Where><And><DateRangesOverlap><FieldRef Name='EventDate' />" +
                            "<FieldRef Name='EndDate' />" +
                                       "<FieldRef Name='RecurrenceID'/>" +
                                       "<Value Type='DateTime'>" +
                                       "<Today />" +
                                       "</Value>" +
                                      "</DateRangesOverlap>" +
                                      "<Eq><FieldRef Name='Room' /><Value Type='Lookup'>" + room + "</Value></Eq>" +
                                      "</And></Where>";

oQueryBookings.ViewFields = string.Concat("<FieldRef Name='Title' />" +
                    "<FieldRef Name='EventDate' />" +
                    "<FieldRef Name='EndDate' />" +
                    "<FieldRef Name='Location' />" +
                    "<FieldRef Name='Description' />" +
                    "<FieldRef Name='fRecurrence' />" +
                    "<FieldRef Name='RecurrenceData' />" +
                    "<FieldRef Name='fAllDayEvent' />" +
                    "<FieldRef Name='LinkTitle'/>" +
                    "<FieldRef Name='Room'/>");

                            oQueryBookings.Query = strQuery;
                            oCollBookings = list.GetItems(oQueryBookings);
                            if (oCollBookings.Count > 0)
                            {
                               //Code Here
                            }

1 Answer 1

0

The issue was with saving the EndDate once end date was saved the entries get fetched correctly with ExpandRecurrence and CalendarDate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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