2012-11-06 39 views
2

我正在使用Outlook加載項將一個窗體區域添加到IPM.Appointment消息類。當顯示此區域時,它將首先向AppointmentItem添加一些屬性。C#Outlook 2010插件 - AppointmentItem.ItemProperties.Add異常

Outlook.AppointmentItem appItem; 

private void FormRegion_FormRegionShowing(object sender, System.EventArgs e) 
{ 
    try 
    { 
     appItem = (Outlook.AppointmentItem)this.OutlookItem; 

     appItem.ItemProperties.Add("CustomProperty", Outlook.OlUserPropertyType.olText); 
    } 
    catch (Exception ex) 
    { 
     MessageBox.Show(ex.ToString()); 
    } 
} 

這工作得很好我的日曆上,但如果我嘗試使用插件與委託日曆,我有兩種編輯器或所有者訪問,它拋出以下異常:

System.UnauthorizedAccessException: You don't have appropriate permission to perform this operation. 
    at Microsoft.Office.Interop.Outlook.Itemproperties.Add(String Name, OlUserPropertType Type, ObjectAddToFolderFields, Object DisplayFormat) 
    at ThisAddin.FormRegion.FormRegion_FormRegionShowing(Ovject sender,EventArgs e) 

任何並感謝所有幫助!

+0

在黑暗中......在委託日曆中不存在'CustomProperty',是嗎? –

+0

沒有。我添加的所有屬性都是專門爲此加載項命名的。作爲一個側面說明,即使嘗試在Outlook窗體設計器中手動添加屬性也會產生相同的錯誤。我開始認爲這可能是Exchange中的權限問題。儘管如此,我已經給測試代表完全控制了郵箱和日曆文件夾,但仍然得到相同的錯誤。 – Jon

+0

我遇到了同樣的問題。你有沒有找到解決方案? – David

回答

3

我通過UserProperties遇到了同樣的問題。對我來說,只有在我第一次嘗試添加屬性時纔會發生異常。所以爲了解決這個問題,我找到了異常並重試。

Outlook.UserProperties properties = appointmentItem.UserProperties; 
Outlook.UserProperty property = null; 
try 
{ 
    property = properties.Add(propertyName, Outlook.OlUserPropertyType.olText); 
} 
catch (System.UnauthorizedAccessException exception) 
{ 
    // the first time didn't work, try again once before giving up 
    property = properties.Add(propertyName, Outlook.OlUserPropertyType.olText); 
}