This first snippet set up the service connection using autodiscover.
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;
//reference: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/e01fe982-83c2-49ee-b900-78d49c47323c/
//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”);
}
}