带FormRegion的VSTO Outlook约会-删除收件人后保存例外

时间:2019-07-15 08:38:01

标签: c# vsto outlook-addin

我为Outlook约会项目创建了一个相邻的窗体区域(使用Visual Studio 2019 for Office 2019),并且在该窗体上有输入,可以将这些值捕获到UserProperty中。

一切正常,直到我添加了一些收件人,发送会议请求,再次打开它,删除收件人然后尝试发送更新为止。

问题是,在窗体区域的close事件上,我检索了所有输入字段的值,并将它们存储在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){}

        }
    }

当约会项被删除时,我可以理解一个例外,但是当您删除收件人时,我不能理解。 因此,尽管UserProperty用于我的预期目的,但是如果要保留FormRegion控件的值,这是否是正确的选择?还是有其他方法可以存储持久性用户数据而无需手动触发save方法?

1 个答案:

答案 0 :(得分:0)

您必须使用OutlookItem属性来获取Outlook项目。

相关问题