如何通过 Outlook 互操作访问已删除的定期约会事件 [英] How to access a deleted recurring appointment occurrence via Outlook interop

查看:96
本文介绍了如何通过 Outlook 互操作访问已删除的定期约会事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一段 C# 代码,可以访问 Outlook 约会重复模式中的异常约会.我意识到当代码尝试访问 Exception 对象的 AppointmentItem 属性时,如果 Exception.Deletedtrue,会有 COM 异常说您更改了此项目的重复之一,此实例不再存在.关闭所有打开的项目并重试."

Hi I have a piece of C# code that access exception appointments in an Outlook appointment recurrence pattern. I realised that when ever the code try to access the AppointmentItem property of the Exception object, if the Exception.Deleted is true, there will be a COM exception saying "You changed one of the recurrences of this item, and this instance no longer exists. Close any open items and try again."

我在代码中获得的主 AppointmentItem 对象直接来自 Folder.Items.ItemChange 事件,这是代码的摘录:

The master AppointmentItem object I obtain in my code is straight from the Folder.Items.ItemChange event and this is an extract of the code:

private static void OnAppointmentChanged(AppointmentItem appointment)
{
    if(appointment.IsRecurring)
    {
        var pattern = outlookAppointment.GetRecurrencePattern();
        foreach (Exception e in pattern.Exceptions)
        {
            // This will throw the exception if e.Deleted == true.
            var occurence = e.AppointmentItem;
        }
    }
}

虽然这个问题已经讨论过在 Visual Studio 论坛中,但标记的解决方案并不是真正的解决方案,因为我的 Outlook 2013 是比解决方案中提到的版本更高的版本(15.0.4693.1001 32 位).

Although this question has been discussed here in the Visual Studio forum, but the marked solution is not really a solution because my Outlook 2013 is a higher version (15.0.4693.1001 32-bit) than the one mentioned in the solution.

有人知道为什么会这样吗?

Does anyone have any idea why this is so?

推荐答案

Deleted 异常类的属性返回一个布尔值,指示 AppointmentItem 是否已从重复模式中删除.它可能不再存在于日历上.

The Deleted property of the Exception class returns a boolean value that indicates whether the AppointmentItem was deleted from the recurring pattern. It may not exist on the calendar anymore.

您可以处理BeforeDelete AppointnentItem 类的事件,该事件在删除项目(它是父对象的实例)之前触发.Appointment 项目的一个实例作为参数传递.您也可以取消将 Cancel 参数设置为 true 的操作.

You can handle the BeforeDelete event of the AppointnentItem class which is fired before an item (which is an instance of the parent object) is deleted. An instance of the Appointment item is passed as a parameter. You may also cancel the action setting the Cancel parameter to true.

很可能有更好的解决方案可以满足您的需求.为什么需要访问不存在的项目?

Most probably there is a better solution which may suits your needs. Why do you need to access non-existing items?

这篇关于如何通过 Outlook 互操作访问已删除的定期约会事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆