VSTO Outlook 插件:当用户拖放定期约会时,无法在 Item_Change 事件中获取 AppointmentItem
Posted
技术标签:
【中文标题】VSTO Outlook 插件:当用户拖放定期约会时,无法在 Item_Change 事件中获取 AppointmentItem【英文标题】:VSTO Outlook Plugin: Cannot get AppointmentItem in Item_Change event when recurring appointment is dragged and dropped by user 【发布时间】:2020-02-24 12:55:21 【问题描述】:我想在 AppointmentItem 上捕获更改事件。我使用 Outlook 2017 进行测试。 为了实现我使用:
我附上了这样的事件:
public void AttachEvents()
_CalendarItems.ItemAdd += Item_Add;
_CalendarItems.ItemChange += Item_Change;
_DeletedItems.ItemAdd += Item_Delete_Add;
Item_Change 方法如下所示:
public void Item_Change(Object item)
if (item != null && item is Outlook.AppointmentItem)
Outlook.AppointmentItem myAppointment = item as Outlook.AppointmentItem;
为了测试代码,我创建了一个定期约会系列。我双击日历中的约会并输入一些标题和正文并保存。 现在我开始我的代码并检查了该项目。 不幸的是,当启动项目更改时,项目指向系列而不是个人约会。 启动 Item_Changed 时如何检索实际的 AppointmentItem?
相关 *** 发帖:Outlook Addin: Moving Appointment in Calendar does not reflect new date/time in AppointmentItem (catch Calendar.ItemChange) 但仍然没有解决办法
关于这个主题的更多信息:
https://www.add-in-express.com/forum/read.php?FID=5&TID=15384 https://social.msdn.microsoft.com/Forums/sqlserver/en-US/4ec55891-fb64-408f-b1cf-4bf05765b866/outlook-get-original-time-of-recurring-exception-item-that-is-opened-with-drag-drop?forum=vsto【问题讨论】:
【参考方案1】:例外不是实际的约会 - 它们作为嵌入式消息附件存储在主约会上。您获得了主约会,并且您需要访问其例外以查看发生了什么变化。
【讨论】:
【参考方案2】:对此有一个棘手的解决方案。 假设:用户使用日历视图更改项目。由于事件是由日历视图引发的,这在所有情况下都应该是正确的:
_CalendarItems = calendarFolder.Items;
_CalendarItems.ItemChange += Item_Change;
[...] 现在我们可以使用 CalendarView 计算选定的 Startdate 并将其与 RecurrencePattern 中存储的所有 Exceptions 进行比较...
if (myAppointment.IsRecurring)
// in case of recurring appointments at this point we always get
// only a reference to the series master NOT the occurrence
// Assumption: The user clicked on the AppointmentItem in the calendar view
// So we can calculate the selected Start Time from this selection range
// then compare this against all Exceptions in the OccurrencePattern of the recurring pattern
// if we find one AppointmentItem in the Exceptions which has the same DateTime then we found the correct one.
//
Outlook.Application application = new Outlook.Application();
Outlook.Explorer explorer = application.ActiveExplorer();
Outlook.Folder folder = explorer.CurrentFolder as Outlook.Folder;
Outlook.View view = explorer.CurrentView as Outlook.View;
// get the current calendar view
if (view.ViewType == Outlook.OlViewType.olCalendarView)
Outlook.CalendarView calView = view as Outlook.CalendarView;
Outlook.RecurrencePattern pattern = myAppointment.GetRecurrencePattern();
for (int i = 1; i <= pattern.Exceptions.Count; i++)
Outlook.Exception myException = pattern.Exceptions[i];
Outlook.AppointmentItem exceptionItem = myException.AppointmentItem;
DateTime itemDateStart = exceptionItem.Start;
if (itemDateStart == calView.SelectedStartTime)
updateMyPluginMeeting(exceptionItem);
return; // the use may only select on AppointmentItem so we can skip the rest
如果您知道任何更好的解决方案,请告诉我。
【讨论】:
以上是关于VSTO Outlook 插件:当用户拖放定期约会时,无法在 Item_Change 事件中获取 AppointmentItem的主要内容,如果未能解决你的问题,请参考以下文章
带有 FormRegion 的 VSTO Outlook 约会 - 删除收件人时保存异常
Outlook VSTO - 当我调用约会.Display() 时如何显示“邀请与会者”文本框?