I am developing a little Outlook AddIn using C# and I cannot get this AddIn to properly cancel the ItemSend process.
I’m hereby thinking of the following scenario:
Consider this small AddIn:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
((Outlook.ApplicationEvents_Event)this.Application).ItemSend += new ApplicationEvents_ItemSendEventHandler(ThisAddIn_ItemSend);
}
void ThisAddIn_ItemSend(object Item, ref bool Cancel)
{
System.Windows.Forms.MessageBox.Show("You can't save it, it's in the past!");
Cancel = true;
return;
}
Now, when I try to change an existing appointment item, I change some values of it when opened in the appointment window, like location, etc. On hitting the “Send” button in the appointment window, the message in the textbox appears as expected. But the problem is that Outlook ignores this cancellation and already saves the changes. The only thing that happens is that the appointment window is not closed. But when simply closing the window without saving explicitly you can see that Outlook has already accepted your changes made to the appointment item.
Is this an intended behaviour? Can Outlook be stopped from saving changes even though the Cancel parameter has been changed to “true”?
You could also use
Application.Inspectors.NewInspectorevent and latch onto theAppointmentItem.Sendevent.According to the
AppointmentItem.SendMSDN documentation – the expected behavior is that the send doesn’t occur whenCancel = true, the inspector window is left open and the changes are still saved – just not sent to attendees.If you want to cancel the Save – you need to latch onto the
AppointmentItem.Writeevent to cancel saves prior to sending.