Search code examples
c#outlookexchange-serverexchangewebservices

Exchange EWS, Calendar FindItems vs FindAppointments?


I followed this guide to retrieve Meetings in Exchange made via Outlook; https://msdn.microsoft.com/en-us/library/office/dn495614(v=exchg.150).aspx

Everything runs fine, no exceptions but it doesn't return any results. I then tried FindItems instead of FindAppointments and this does return my results. Why does FindAppointments not return the meetings?

I'm creating test appointments in Outlook online. By clicking Menu > Calendar > New, I complete the details of the event and then add attendees before saving. These are returned by FindItems() but there doesn't seem to be a property to retrieve Location and Attendee list? Where FindAppointments would give me the properties I need if the data was returned. I have had Outlook installed on a computer previously where creating a meeting specifically mentions the word 'Meeting' where this appears to be calendar items. I'm not sure what the difference is?

My end goal is when users schedule meetings via Outlook and I'll have an application that retrieves details of those meetings inc. an attendee list and location.

Many thanks for any pointers!


Solution

  • Manged to find a solution taken from this thread

    The code could do with a tidy up but it correctly pulls down the appointments and allows me to get the data that I need.

    FindItemsResults<Item> result = service.FindItems(WellKnownFolderName.Calendar, new CalendarView(DateTime.Now, DateTime.Now.AddDays(7)));
                foreach(Item item in result.Items)
                {
                    ServiceResponseCollection<GetItemResponse> itemResponseCollection = service.BindToItems(new[] { new ItemId(item.Id.UniqueId) }, new PropertySet(BasePropertySet.FirstClassProperties));
                    foreach(GetItemResponse itemResponse in itemResponseCollection)
                    {
                        Appointment appointment = (Appointment)itemResponse.Item;
                        Console.WriteLine("Subject: " + appointment.Subject);
                        Console.WriteLine("Location: " + appointment.Location);
    
                        Console.WriteLine("AppointmentType: " + appointment.AppointmentType.ToString());
                        Console.WriteLine("Body: " + appointment.Body);
                        Console.WriteLine("End: " + appointment.End.ToString());
                        Console.WriteLine("UniqueId: " + appointment.Id.UniqueId);
                        Console.WriteLine("Start: " + appointment.Start.ToString());
                        Console.WriteLine("When: " + appointment.When);
    
                        Console.WriteLine("Required Attendees: ");
                        foreach (var attendee in appointment.RequiredAttendees)
                        {
                            Console.WriteLine(attendee.Name);
                        }
                    }