0

I am developing an ASP.NET web app using Microsoft Exchange Web Services (managed API). My goal is to provide a list of conference room addresses as input, and get back busy/free info from the Exchange server using GetUserAvailability so that I can suggest an open conference room to the user for a given meeting time. I have working code, but when I try to limit the DetailedSuggestionsWindow to the meeting duration, I get an error:

The time duration specified for FreeBusyViewOptions.TimeWindow is invalid.

I know I can expand the time window - but then I'm getting more data back than I need. Can anyone provide a way to find a suggested conference room for a certain time (typically 30 mins - 2 hrs)?

akerra
  • 1,017
  • 8
  • 18
  • What time window are you trying to use ? Why is too much data a problem for you ? if you are getting the correct data just filter out what you don't need at the client. I would suggest you include the code your try in your question as that will help people trying to answer. – Glen Scales Dec 04 '18 at 01:43
  • @GlenScales because EWS seems to be choosing optimal meeting windows where the maximum number of attendees are available, not providing free/busy info for an exact timeframe. So if I know I want a meeting from 2-3, and I supply a 24 hour window, I'm not guaranteed to get back for the timeslot I care about if it's not one of the best results. I don't really care what percentage of attendees are available, just that at least one attendee (Conf. room) is available. I tried your suggestion, and did post-filtering to see if it returned the expected result and it did not. – akerra Dec 04 '18 at 13:48
  • Possible duplicate of [Difference between a DateTime object I create and DateTime.Now](https://stackoverflow.com/questions/8750937/difference-between-a-datetime-object-i-create-and-datetime-now) – akerra Dec 05 '18 at 14:33

2 Answers2

0

You could refer to the below link:

// Create a collection of attendees. 
List<AttendeeInfo> attendees = new List<AttendeeInfo>(); 

attendees.Add(new AttendeeInfo() 
{ 
    SmtpAddress = "mack@contoso.com", 
    AttendeeType = MeetingAttendeeType.Organizer 
}); 

attendees.Add(new AttendeeInfo() 
{ 
    SmtpAddress = "sadie@contoso.com", 
    AttendeeType = MeetingAttendeeType.Required 
}); 

// Specify options to request free/busy information and suggested meeting times.
AvailabilityOptions availabilityOptions = new AvailabilityOptions(); 
availabilityOptions.GoodSuggestionThreshold = 49; 
availabilityOptions.MaximumNonWorkHoursSuggestionsPerDay = 0;
availabilityOptions.MaximumSuggestionsPerDay = 2;
// Note that 60 minutes is the default value for MeetingDuration, but setting it explicitly for demonstration purposes.
availabilityOptions.MeetingDuration = 60; 
availabilityOptions.MinimumSuggestionQuality = SuggestionQuality.Good; 
availabilityOptions.DetailedSuggestionsWindow = new TimeWindow(DateTime.Now.AddDays(1), DateTime.Now.AddDays(2));
availabilityOptions.RequestedFreeBusyView = FreeBusyViewType.FreeBusy;

// Return free/busy information and a set of suggested meeting times. 
// This method results in a GetUserAvailabilityRequest call to EWS.
GetUserAvailabilityResults results = service.GetUserAvailability(attendees, 
                                                                 availabilityOptions.DetailedSuggestionsWindow, 
                                                                 AvailabilityData.FreeBusyAndSuggestions, 
                                                                 availabilityOptions); 

For more information, please refer to this link:

Get appointments from coworker via EWS only with “Free / Busy time, subject, location” permission level

Alina Li
  • 884
  • 1
  • 6
  • 5
  • This is the code I'm using. When I decrease the `DetailedSuggestionTimeWindow`, to a typical meeting duration, I get the error described. – akerra Dec 04 '18 at 13:43
  • According to my search, this actually appears to be an issue in the GetUserAvailability method as opposed to any DateTime manipulation. For more information, please refer to this link: https://stackoverflow.com/questions/8750937/difference-between-a-datetime-object-i-create-and-datetime-now – Alina Li Dec 05 '18 at 01:27
  • Thank you. I was hoping there was a better way to get only the info desired, but it doesn't look like there is. I will flag my question as a duplicate. – akerra Dec 05 '18 at 14:32
0

According to https://learn.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.exchangeservice.getuseravailability

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.

So, you can't pass the time window you want. Try removing the attendees and querying for availability of only rooms to get a more complete result set back.

stefann
  • 1,045
  • 10
  • 14