Jon*_*Jon 3 c# vsto outlook-addin outlook-2010
我正在开发一个 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());
}
}
Run Code Online (Sandbox Code Playgroud)
这在我的日历上运行良好,但如果我尝试将插件与我具有编辑者或所有者访问权限的委托日历一起使用,则会引发以下异常:
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)
Run Code Online (Sandbox Code Playgroud)
感谢任何和所有的帮助!
小智 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);
}
Run Code Online (Sandbox Code Playgroud)