I am trying to write an addin that notices when an appointment is saved and does some data. For that, I need to check whether, when the active inspector is closed, the item is saved or not.
My problem is this: when trying to bind a WriteEvent
-listener to the current item in the FormRegionShowing
-method, I need the ActiveInspector
to event get the current item. However, when getting the ActiveInspector
there, it is null
, probably, because that method is called before the active inspector is actually active.
When trying to bind it in the FormRegionClosed
-method, however, the write event never fires. So, how do I know when an AppointmentItem
is actually saved by the user?
EDIT: I managed to bind the write event in the FormRegionShowing
-method, but it still won't fire:
private void ADDIN_NAME_FormRegionShowing(object sender, System.EventArgs e){
Outlook.AppointmentItem currentItem = (Outlook.AppointmentItem)this.OutlookItem;
currentItem.Write += new Outlook.ItemEvents_10_WriteEventHandler(currentItem_Write);
currentItem.AfterWrite += new Outlook.ItemEvents_10_AfterWriteEventHandler(currentItem_AfterWrite);
MessageBox.Show("added handlers");
}
void currentItem_AfterWrite(){
MessageBox.Show("item has been saved");
}
void currentItem_Write(ref bool Cancel){
MessageBox.Show("item being saved");
}