How to do paging with Exchange Web Services CalendarView

Viewed 7538

If I do this:

_calendar = (CalendarFolder)Folder.Bind(_service, WellKnownFolderName.Calendar);

var findResults = _calendar.FindAppointments(
    new CalendarView(startDate.Date, endDate.Date)
);

I sometimes get an exception that too many items were found.

"You have exceeded the maximum number of objects that can be returned for the find operation. Use paging to reduce the result size and try your request again."

CalendarView supports a constructor that will let me specify MaxItemsReturned, but I can't figure out how I would call it again, specifying the offset for paging. ItemView has this constructor:

 public ItemView(int pageSize, int offset)

And the usage of that is obvious.

What about CalendarView? How does one do paging with a CalendarView?

I could reduce the date range to be a shorter span, but there's still no way of determining if it will work for sure.

3 Answers

You can still paginate the FindAppointments function manipulating the CalendarView start dates.

var cal = CalendarFolder.Bind(_service, WellKnownFolderName.Calendar);
var cv = new CalendarView(start, end, 1000);

var appointments = new List<Appointment>();

var result = cal.FindAppointments(cv);

appointments.AddRange(result);

while (result.MoreAvailable)
{
     cv.StartDate = appointments.Last().Start;

     result = cal.FindAppointments(cv);

     appointments.AddRange(result);
}

Though I don't know if they come in order. If they don't you might have to use the last envent start date and remove the duplicates.

Related