Philippsen's Blog

Everyday findings in my world of .net and related stuff

Reading extended properties using EWS managed API

Posted by Torben M. Philippsen on June 20, 2011

Having been working with Exchange 2007 Web Services (EWS) for a couple af years a recent bug led me to testing various scenarios regarding appointment items using the EWS Managed API instead of the proxy classes that I have grown used to working with.

One of my struggles was to read the extended properties that we use. Having gotten it all to work I though that I’d create this post. Below you will find my code sample:

This first snippet set up the service connection using autodiscover.

        private ExchangeService GetService()


            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2007_SP1);

            service.Credentials = new NetworkCredential(Settings.Default.ConnectingUser, Settings.Default.ConnectingUserPassword, Settings.Default.ConnectingUserDomain);

            service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SID, Settings.Default.ImpersonatedUserSID);

            service.Url = new Uri(Settings.Default.EWSURL);

            return service;


This second snippet defines and fetches the standard properties as well as the extended properties.

        private void btnGetItem_Click(object sender, EventArgs e)


            string itemId = txtItemId.Text;

            ExchangeService service = GetService();

            AlternateId sourceId = new AlternateId(IdFormat.EwsLegacyId, itemId, Settings.Default.ImpersonatedUserMailbox);

            AlternateId destinationId = service.ConvertId(sourceId, IdFormat.EwsId) as AlternateId;


            //define the extended properties that should be fetched

            ExtendedPropertyDefinition rmsIsRms = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, “RMS-IsRMS”, MapiPropertyType.Boolean);

            ExtendedPropertyDefinition rmsCustomerProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, “RMS-CustomerProp”, MapiPropertyType.String);

            ExtendedPropertyDefinition rmsInternalProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, “RMS-InternalProp”, MapiPropertyType.Boolean);

            ExtendedPropertyDefinition rmsProjectProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, “RMS-ProjectProp”, MapiPropertyType.String);

            ExtendedPropertyDefinition rmsActivityProp = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, “RMS-ActivityProp”, MapiPropertyType.String);

            ExtendedPropertyDefinition[] userFields = new ExtendedPropertyDefinition[] { rmsIsRms, rmsActivityProp, rmsCustomerProp, rmsInternalProp, rmsProjectProp };

            //get the item and it’s extended properties

            PropertySet extendedPropertySet = new PropertySet(BasePropertySet.FirstClassProperties, userFields);

            Appointment item = (Appointment)Item.Bind(service, new ItemId(destinationId.UniqueId), extendedPropertySet);

            //having the item – get the extended properties

            object isRMS;

            object customerProp;

            object isInternalProp;

            object projectProp;

            object activityProp;

            //Print properties

            rtItemProps.AppendText(“ItemClass: “ + item.ItemClass + “\n”);

            rtItemProps.AppendText(“Subject: “ + item.Subject + “\n”);

            rtItemProps.AppendText(“CalendarItemType: “ + item.AppointmentType.ToString() + “\n”);

            rtItemProps.AppendText(“Organizer: “ + item.Organizer.Name + “\n”);

            rtItemProps.AppendText(“OrganizerEmail: “ + item.Organizer.Address + “\n”);

            rtItemProps.AppendText(“Start: “ + item.Start + “\n”);

            rtItemProps.AppendText(“End: “ + item.End + “\n”);

            rtItemProps.AppendText(“Location: “ + item.Location + “\n”);

            rtItemProps.AppendText(“Free/busy: “ + item.LegacyFreeBusyStatus.ToString() + “\n”);

            rtItemProps.AppendText(“—————RMS INFO————–\n”);

            //extended properties are printed only if they exist

            if (item.TryGetProperty(rmsIsRms, out isRMS) && isRMS != null)


                rtItemProps.AppendText(“IsRMS: “ + isRMS.ToString() + “\n”);


            if (item.TryGetProperty(rmsCustomerProp, out customerProp) && customerProp != null)


                rtItemProps.AppendText(“Customer: “ + customerProp.ToString() + “\n”);


            if (item.TryGetProperty(rmsProjectProp, out projectProp) && projectProp != null)


                rtItemProps.AppendText(“Project: “ + projectProp.ToString() + “\n”);


            if (item.TryGetProperty(rmsActivityProp, out activityProp) && activityProp != null)


                rtItemProps.AppendText(“Activity: “ + activityProp.ToString() + “\n”);


            if (item.TryGetProperty(rmsInternalProp, out isInternalProp) && isInternalProp != null)


                rtItemProps.AppendText(“IsInternal: “ + isInternalProp.ToString() + “\n”);




5 Responses to “Reading extended properties using EWS managed API”

  1. Kevin Reed said

    Very helpful.

  2. Before you worked out this solution, were you getting an error message about ‘FieldUri’ not being set?

  3. No, I am sorry – I don’t recall having that problem. What exactly are You struggling with?

  4. If you were to open an Appointment in Outlook and view its properties (File -> Properties in the ribbon) I am trying to read the value(s) for the “Contacts…” field. I’m trying to do this via the Exchange Managed API.

    • I haven’t done that myself using the managed API – but I have accomplished the same using the EWS proxy classes – well that doesn’t help You much:-)
      Do You know EWS editor? It’s an Open Source util developed by Microsoft to demonstrate how the managed API works. With a little investigation, I would think You would be able to find what You are looking for in the code of EWS edtitor. You can read more about EWS editor as well as download the complete source from this link: Hope this helps…

Sorry, the comment form is closed at this time.

%d bloggers like this: