3

我正在开发一个将表单区域添加到 IPM.Appointment 消息类的 Outlook 加载项。当这个区域显示出来时,它首先会向 AppointmentItem 添加一些属性。

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)

任何和所有的帮助表示赞赏!

4

1 回答 1

4

我通过 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);
}
于 2014-10-21T13:34:35.270 回答