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 protected]");
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 protected]") }, 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.
Maybe it has something to do with the difference between your time zone and UTC, producing a negative time window. Try increasing from AddHours(8) to bigger values up to AddHours(24) and see what happens.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With