Create an advanced property using EWS and access it from an Outlook add-in

I am currently working on EWS to have some integration of our enterprise application with Exchange 2010. I use EWS to create an appoinment for Exchange 2010, and it works great; but lately I tried to add some custom / extended property when creating a meeting, below my code adds an extended property.

Dim customField As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "MyCustomField", MapiPropertyType.String)

appointment.SetExtendedProperty(customField, "CustomFieldValue")

The above codes can create a custom field for assignment.

Now here is my problem. When I open an appointment in Outlook that I created and go to "Developer> Design this form" and then the "All Fields" tab, I see only the custom field that I created in the "Custom field in the folder" but not in "Custom field in this item. "

I also create an Outlook add-in to respond to a custom field that I created using EWS when a user opens a meeting in Outlook, when I tried to find a custom field, I could not find a custom field because the custom field is created in the "Custom field in folder "but not in" User Defined Field on this item ".

These are codes in the Outlook add-in and will be executed when the user opens the meeting in Outlook. But since the user field is not in "in this element",. Find () returns Nothing.

Dim appt As Outlook.AppointmentItem
appt = TryCast(inspector.CurrentItem, Outlook.AppointmentItem)
If appt.UserProperties.Find("MyCustomField") Is Nothing Then
    'Some action
Else
    'Some action
End If

What I want to achieve is to create an appointment with a custom field (advanced property) using EWS, and then read the custom field (advanced property) in the Outlook add-in when the user opens the appointment in Outlook.

EDIT:

The value that I assigned to the custom field using EWS is shown in "Custom field in folder." How to get value from my Outlook add-in? Maybe I can get the value and add a custom field to the element and with the value?

Thank.

+3
source share
2 answers

: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/2a98b4ab-0fbc-4863-8303-48711a18a050

, EWS, UserProperties. PropertyAccessor.

outlookItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/yourProp")
+6

, - (Delphi) , .
AAppointmentItem - OLEVariant

const
   GUID_PS_PUBLIC_STRINGS = '{00020329-0000-0000-C000-000000000046}';
   cPublicStringNameSpace = 'http://schemas.microsoft.com/mapi/string/' + GUID_PS_PUBLIC_STRINGS + '/';

var
   lPropertyAccessor: OleVariant;
   lSchemaName, lValue: String;

begin   
   // Use the PropertyAccessor because Outlook UserProperties() can't access the extended properties created by EWS 
   // Use the 'string subnamespace of the MAPI namespace' (http://msdn.microsoft.com/en-us/library/office/ff868915.aspx)
   // with the PS_PUBLIC_STRINGS GUID from http://msdn.microsoft.com/en-us/library/bb905283%28v=office.12%29.aspx
   lPropertyAccessor := AAppointmentItem.PropertyAccessor;
   lSchemaName := cPublicStringNameSpace + PROPERTY_TIMETELLID;  // Name constants defined elsewhere
   try
      lSchemaName := cPublicStringNameSpace + PROPERTY_TIMETELLID;
      lValue := lPropertyAccessor.GetProperty(lSchemaName);
      lEvent.CustSyncTTID := StrToInt(lValue);
   except
   end;
   try
      lSchemaName := cPublicStringNameSpace + PROPERTY_TIMETELLSYNCTIME;
      lValue := lPropertyAccessor.GetProperty(lSchemaName);
      lEvent.CustSyncDate := UTCString2LocalDateTime(lValue);
   except
   end;
   try
      lSchemaName := cPublicStringNameSpace + PROPERTY_TIMETELLSYNCID;
      lValue := lPropertyAccessor.GetProperty(lSchemaName);
      lEvent.CustSyncEntryID := lValue;
   except
   end;

try, ; "" (http://blog.depauptits.nl/2012/04/safely-accessing-named-properties-in.html)

, , GetProperties() .

FWIW, UserProperties (lProperty - OLEVariant)

lProperty := AAppointmentItem.UserProperties.Find(PROPERTY_TIMETELLID);
if IDispatch(lProperty) <> nil then
  lEvent.CustSyncTTID :=  lProperty.Value;
lProperty := AAppointmentItem.UserProperties.Find(PROPERTY_TIMETELLSYNCTIME);
if IDispatch(lProperty) <> nil then
  lEvent.CustSyncDate :=  lProperty.Value;
lProperty := AAppointmentItem.UserProperties.Find(PROPERTY_TIMETELLSYNCID);
if IDispatch(lProperty) <> nil then
  lEvent.CustSyncEntryID := lProperty.Value;            

[ 2013-6-10]

, GetProperties ( MS):

lPropertyAccessor := AAppointmentItem.PropertyAccessor;
lSchemas := VarArrayOf([cPublicStringNameSpace + PROPERTY_TIMETELLID,
                        cPublicStringNameSpace + PROPERTY_TIMETELLSYNCTIME,
                        cPublicStringNameSpace + PROPERTY_TIMETELLSYNCID]);
try
  lValues := lPropertyAccessor.GetProperties(lSchemas);
  if VarType(lValues[0]) <> varError then
     lEvent.CustSyncTTID := lValues[0];
  if VarType(lValues[1]) <> varError then
  begin
     lDT := lValues[1];
     lDT := TTimeZone.Local.ToLocalTime(lDT);
     lEvent.CustSyncDate := lDT;
  end;
  if VarType(lValues[2]) <> varError then
    lEvent.CustSyncEntryID := lValues[2];
except
end;
0

All Articles