【发布时间】:2019-07-15 08:38:01
【问题描述】:
我为 Outlook 约会项目创建了一个相邻的表单区域(使用 Visual Studio 2019 for Office 2019),并且我在该表单上有输入,我从中将值捕获到 UserProperties 中。
一切正常,直到我添加了一些收件人,发送了会议请求,再次打开它,删除了收件人,然后尝试发送更新。
问题在于,在表单区域的关闭事件中,我检索所有输入字段的值,将它们存储在 UserProperties 中,然后触发项目的 .Save() 方法,这会引发异常。
发生这种情况时,我的 UserPropery 值不会保存,但约会正文和收件人列表确实会保存。
在删除约会项目时,save 方法也会抛出异常,这是可以理解的。我将它包装在 try..catch 中。
我的代码示例:
private void AdditionalAppointmentInfo_FormRegionClosed(object sender, System.EventArgs e)
{
if (customItem) //In the FormRegionShowing Event, I check for UserProps to see if this is an item created by this add-in
{
try
{
item.UserProperties["MyUserProperty"].Value = MyTextBox.Text;
item.Save(); //Throws exception here when a recipient gets removed.
}
catch (System.Exception ex){}
}
else
{
try
{
item.UserProperties.Add("IsCustomItem", OlUserPropertyType.olText).Value="1"; //set a property to indicate that this item was created using this add-in
item.UserProperties.Add("MyUserProperty", OlUserPropertyType.olText).Value = MyTextBox.Text;
}
catch (System.Exception){}
}
}
我可以理解约会项目被删除时的例外情况,但当您删除收件人时则不会。 因此,虽然 UserProperties 适用于我的预期目的,但如果您希望 FormRegion 控件的值保持不变,那么使用它是否正确?还是有其他方法可以存储持久的用户数据而无需手动触发保存方法?
【问题讨论】:
-
您从哪里获得代码示例中使用的
item对象? -
它在 FormRegionShowing 事件中被初始化,如下所示:
item=(AppointmentItem)this.OutlookItem;
标签: c# vsto outlook-addin