C# Outlook 2010插件 - AppointmentItem.ItemProperties.Add异常

3

我正在开发一个Outlook插件,它可以为IPM.Appointment消息类添加表单区域。当该区域被显示时,它将首先向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)

非常感谢您的帮助!


猜测一下...CustomProperty在委托日历中已经存在了吗? - Kevin Pope
不是。我添加的所有属性都是专门为此插件命名的。另外,即使在Outlook表单设计器中手动添加属性也会产生相同的错误。我开始认为这可能是Exchange中的权限问题。尽管如此,我已经给测试委托人完全控制邮箱和日历文件夹,仍然得到相同的错误。 - Jon
我也遇到了同样的问题。你找到解决方案了吗? - David
我通过在尝试添加UserProperty之前对AppointmentItem调用Save来解决了这个问题。 - David
1个回答

5

我通过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);
}

疯狂,但实际上确实有效... - Indigo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接