Search code examples
c#vstooutlook-addin

How do you find the next available time when creating an Appointment using C# VSTO


I've written the following code in C# to create a new appointment with 1 attendee (and me). But the start time isn't automatically defaulted to the next available free time.

AppointmentItem newAppointment = Globals.ThisAddIn.Application.CreateItem(OlItemType.olAppointmentItem);
newAppointment.MeetingStatus = OlMeetingStatus.olMeeting;

Recipients recipients = newAppointment.Recipients;
Recipient readyByRecipient = null;
readyByRecipient = recipients.Add(emailAddress);
readyByRecipient.Type = (int)OlMeetingRecipientType.olRequired;
recipients.ResolveAll();
newAppointment.Display();

Marshal.ReleaseComObject(readyByRecipient);
Marshal.ReleaseComObject(recipients);
Marshal.ReleaseComObject(newAppointment);

Can someone please show me how I can default the appointment start time to the next available free time for all attendees?

Or how to programmatically work out when the next available free time is for all attendees?


Solution

  • Use Recipient.FreeBusy (or AddressEntry.GetFreebusy) to see what the available time slots are. You can do that for the current user (Application.Session.CurrentUser) and/or the appointment attendees.