VSTO Addin Outlook Appointment delete and write event fired only if opened first

1.3k views Asked by At

I am working on an Outlook Addin where I try to perform a specific action if deleted. It works fine with all the appointments that I have already opened once. When the appointment is created or deleted from the calendar without being open first no event (BeforeDelete, Write) is fired.

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    inspectors = this.Application.Inspectors;
    inspectors.NewInspector +=
    new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
}
void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
    appointmentItem = Inspector.CurrentItem as Outlook.AppointmentItem;
    if (appointmentItem != null)
    {
        (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Send += _appointment_Send;
        (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).BeforeDelete += _appointment_Delete;
        (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Write += _appointment_Write;    
        (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Open += _appointment_Open;
        (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Close += _appointment_Close;
    }
}

I would assume that the explanation lies in the fact inspectors are only attached when the appointment is open and that the path to follow is something more like described here but I am not sure. The above code works like a charm excepted for the specific case where the appointment is not opened before being deleted or created.

Any guidance will be much appreciated.

1

There are 1 answers

1
Dmitry Streblechenko On

Yes, BeforeWrite does not fire. If I select an appointment in Outlook and look at the events fired by OOM using OutlookSpy (I am its author - select the appointment, click Item button, go to the Events tab and look at the log at the bottom of the page, modify the appointment inline), I can only see the following events fire.

BeforeDelete fires as expected when the appointment is deleted.

PropertyChange (ConversationIndex)
PropertyChange (Subject)
PropertyChange (Start)
PropertyChange (StartInStartTimeZone)
PropertyChange (StartUTC)
PropertyChange (End)
PropertyChange (EndInEndTimeZone)
PropertyChange (EndUTC)
PropertyChange (Duration)
PropertyChange (AllDayEvent)
PropertyChange (StartInStartTimeZone)
PropertyChange (StartUTC)
PropertyChange (End)
PropertyChange (EndInEndTimeZone)
PropertyChange (EndUTC)
PropertyChange (Start)
PropertyChange (EndInEndTimeZone)
PropertyChange (EndUTC)
PropertyChange (Duration)
PropertyChange (End)
PropertyChange (MeetingStatus)
Write (false)
BeforeCheckNames (false)
AfterWrite ()
<Unknown(DispID=0x0000FC95)> (false)