Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
206 views
in Technique[技术] by (71.8m points)

c# - How to access a deleted recurring appointment occurrence via Outlook interop

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."

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;
        }
    }
}

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...