0
votes

My Outlook Addin adds info to each AppointmentItem which should get deleted in case the AppointmentItem gets deleted (user hits delete on AppointmentItem in the Calendar).

For this I use the following event handling. On startup I attach to the trash folder:

[...]

Outlook.MAPIFolder trashFolder =
                currentExplorer.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
            _DeletedItems = trashFolder.Items;
            _DeletedItems.ItemAdd += Item_Delete_Add;

[...]

Item_Delete_Add gets called when the user hits delete on an appointment series and the user selects "whole series":

[...]

    if (myAppointment.RecurrenceState == Outlook.OlRecurrenceState.olApptMaster)
    {
        DialogResult dialogResult = MessageBox.Show(Resources.Resources.DeleteAllAgreeDoMeetingsInSeries, Resources.Resources.AlsoDeleteAgreeDoMeeting_DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
        if (dialogResult == DialogResult.Yes)
        {                    
            Outlook.RecurrencePattern pattern = myAppointment.GetRecurrencePattern();
            foreach (Outlook.Exception exception in pattern.Exceptions)
            {
                if (!deleteAppointment(exception.AppointmentItem,true))
                {
                    wasSuccessfull = false;
                }
            }
        }
    } else

[...]

When accessing exception.AppointmentItem the following COMException is thrown: enter image description here

The german exception description translates to something: You have changed an element of this series. and this instance is not available anymore. Close all elements and try again.

So the question boils down to: How can I handle the deletion of an appointment series in a way so I can handle each exception within the series individually (i.e. delete data stored in that exceptions).

1

1 Answers

1
votes

Found the solution here

You just need to check whether the exception has already been deleted by modifying the above code:

[...]

    if (myAppointment.RecurrenceState == Outlook.OlRecurrenceState.olApptMaster)
    {
        DialogResult dialogResult = MessageBox.Show(Resources.Resources.DeleteAllAgreeDoMeetingsInSeries, Resources.Resources.AlsoDeleteAgreeDoMeeting_DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
        if (dialogResult == DialogResult.Yes)
        {                    
            Outlook.RecurrencePattern pattern = myAppointment.GetRecurrencePattern();
            foreach (Outlook.Exception exception in pattern.Exceptions)
            {
                if (!exception.Deleted)
                {
                    if (!deleteAppointment(exception.AppointmentItem, true))
                    {
                        wasSuccessfull = false;
                    }
                }
            }
        }
    } else

[...]

At least this avoids COMExceptions.