Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...