Frage

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
                            }
War es hilfreich?

Lösung

The issue was with saving the item, the EventDate & EndDate were saved as the same day.

Andere Tipps

The problem is you are using <Today/>. You are already setting the CalendarDate property on the query so I'd recommend you use <Week/> or <Month/> instead to get the rest of the items.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top