[英]On some outlook installations I cannot access the email internet headers so add-in fails
[英]Creating extended property using EWS and access it from Outlook Add-in
我目前正在使用EWS將我們的公司應用程序與Exchange 2010集成在一起。我正在使用EWS創建對Exchange 2010的任命,它運行正常; 但最近我嘗試在創建約會時添加一些自定義/擴展屬性,下面是我添加擴展屬性的代碼。
Dim customField As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "MyCustomField", MapiPropertyType.String)
appointment.SetExtendedProperty(customField, "CustomFieldValue")
以上代碼能夠為約會創建自定義字段。
現在這是我的問題。 當我打開我創建的Outlook中的約會並轉到“開發人員>設計此表單”,然后“所有字段”選項卡時,我只看到我在“文件夾中的用戶定義字段”中創建的自定義字段,但不是“此項中用戶定義的字段”。
我還制作一個Outlook加載項,以便在用戶在Outlook中打開約會時使用EWS創建自定義字段,當我嘗試查找自定義字段時,無法找到自定義字段,因為自定義字段在“文件夾中的用戶定義的字段”中創建,但不在“此項目中的用戶定義的字段”中創建。
這是Outlook加載項中的代碼,將在用戶在Outlook中打開apointment時執行。 但由於自定義字段不在“此項目中”,因此.Find()返回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
我想要實現的是使用EWS創建自定義字段(擴展屬性)的約會,然后在用戶在Outlook中打開約會時讀取Outlook加載項中的自定義字段(擴展屬性)。
編輯:
我使用EWS分配給自定義字段的值顯示在“文件夾中的用戶定義字段”中。 如何從Outlook加載項中檢索值? 也許我可以檢索值並將自定義字段添加到項目並使用值?
謝謝。
答案在這里: http : //social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/2a98b4ab-0fbc-4863-8303-48711a18a050
無法使用UserProperties訪問EWS創建的擴展屬性。 但是可以使用PropertyAccessor進行訪問。
outlookItem.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{00020329-0000-0000-C000-000000000046}/yourProp")
我發布這個作為另一個答案顯示一些實際(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;
請注意許多嘗試例外,因為我們正在進行后期綁定; '早'會更好( 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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.