我正在开发一个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)
感谢任何和所有帮助!
答案 0 :(得分: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);
}