Exchange Web Services and Property Sets
Asked Answered
S

3

6

I need to retrieve calendar information by invoking the Exchange Web Service in BPOS. I'm using a CalendarView with a PropertySet to retrieve as little data as possible. However, property sets seems to be limited. I need the EmailAddress of the one who made the calendar appointment so I thought I could use the AppointmentSchema.Organizer in the PropertySet.

When fetching a whole appointment I can get the e-mail through appt.Organizer.EmailAddress. But with the code below the Organizer.EmailAddress is always null. I've enabled the trace and checked it and only the Organizer.Name property is sent, nothing else. Does anyone have a solution on how to get the EmailAddress when using a PropertySet?

CalendarView view = new CalendarView(dtFrom, dtTo);
view.PropertySet = new PropertySet(ItemSchema.Subject);
view.PropertySet.Add(ItemSchema.Id);
view.PropertySet.Add(AppointmentSchema.Start);
view.PropertySet.Add(AppointmentSchema.End);
view.PropertySet.Add(AppointmentSchema.Organizer); // This should contain EmailAddress but it doesn't

Mailbox mailbox = new Mailbox("[email protected]");
FolderId id = new FolderId(WellKnownFolderName.Calendar, mailbox);
CalendarFolder folder = CalendarFolder.Bind(service, id);
FindItemsResults<Appointment> findResults = folder.FindAppointments(view);
Syracuse answered 30/4, 2009 at 9:38 Comment(0)
A
6

This should work (does for me):

service.FindAppointments(WellKnownFolderName.Calendar, new CalendarView(start, end)).Where(s => DateTime.Now < s.Start);
service.LoadPropertiesForItems(appointments, PropertySet.FirstClassProperties);
Aspergillus answered 20/7, 2011 at 18:25 Comment(0)
C
1

As best as I have been able to figure out EWS is a little buggy when it comes to populating the full EmailAddress details both in Appointments for Organizer and for other things like "EmailMessage.From". When you do a query for multiple items, you don't get the EmailAddress properties being fully populated. E.g. using APIs like:

Folder.FindItems
ExchangeService.FindAppointments

I find that only the display name in the EmailAddress fields gets populated.

To get the EmailAddress fully populated I find I need to load/bind to the specific item and specify the relevant EmailAddress property, e.g. AppointmentSchema.Organizer in your case. So although you specify exactly the same property to load, you are loading using a single item call rather than a bulk query. E.g. using:

ServiceObject.Load

Which is available for both Appointment and EmailMessage as they both derive off ServiceObject. Using Item.Bind with the appropriate property set defined should also work.

As an aside I figured this out looking at the code for EwsEditor which is mentioned here:

http://blogs.msdn.com/webdav_101/archive/2009/11/10/ews-has-more-happy-now-ews-managed-api-and-ewseditor.aspx

The usability of EwsEditor is fairly sucky, and the code takes some trawling to figure out, but at least it does show examples of exercising many of the APIs.

Cortezcortical answered 8/4, 2010 at 7:22 Comment(0)
E
0
service.FindAppointments(WellKnownFolderName.Calendar, new CalendarView(start, end)).Where(s => DateTime.Now < s.Start);
service.LoadPropertiesForItems(appointments, PropertySet.FirstClassProperties);

It worked for me.

Erelia answered 25/2, 2013 at 8:20 Comment(1)
Isn't this just a copy of the answer by @Jordan? If you're trying to say that answer worked for you, you should post that message as a comment on that answer.Bradlybradman

© 2022 - 2024 — McMap. All rights reserved.