I'm trying to use the Exchange 2007 API to query calendar availability for a specific user. My sample code is producing the following exception:
The time duration specified for FreeBusyViewOptions.TimeWindow is invalid.
Here's the sample code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
service.AutodiscoverUrl("email@domain.com");
DateTime startTime = new DateTime(2012, 1, 6, 7, 0, 0);
TimeWindow tw = new TimeWindow(startTime, startTime.AddHours(8));
GetUserAvailabilityResults result = service.GetUserAvailability(new List<AttendeeInfo> { new AttendeeInfo("email@domain.com") }, tw, AvailabilityData.FreeBusyAndSuggestions);
The wierd thing is, if I replace my startTime assignment with the following it works:
DateTime startTime = DateTime.Now;
What's the difference between the DateTime object I created and the object produced by DateTime.Now. I've examined them in detail while debugging and can't find a difference.
Any ideas?
This actually appears to be an issue in the GetUserAvailability method as opposed to any DateTime manipulation.
According to the MSDN documentation:
The GetUserAvailability(Generic ,TimeWindow,AvailabilityData,AvailabilityOptions) method supports only time periods that are a minimum of 24 hours long and that begin and end at 12:00a.m. To restrict the results of the method to a shorter time period, you must filter the results on the client.