【问题标题】:VSTO Outlook Appointment with FormRegion - save exception when recipient removed带有 FormRegion 的 VSTO Outlook 约会 - 删除收件人时保存异常
【发布时间】: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


【解决方案1】:

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

【讨论】:

  • 您是否在其他事件处理程序中遇到任何错误?你得到了哪个例外?
  • 它只是说:'该项目无法保存',而删除时的异常说:'该项目已被删除或移动'
  • 我建议选择另一个事件处理程序。尝试使用docs.microsoft.com/en-us/office/vba/api/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多