Search code examples
c#outlook-addin

Prevent Move Appointment Item from Calendar via Outlook Add-In


I'm writing an Outlook Add-In for appointments & meetings. It's integrated with a web service. After write event, I'm calling web service with start and end dates. Or after a delete, I aslo call web service. These're OK.

But, if user moves item in calendar, start and end dates changing but I can't get informed about it. Or if deletes it too.

For an Appointment Item in calendar, how can I get an "event" to prevent moving, deleting that item?


Solution

  • You may find the following events helpful:

    • The BeforeDelete event of Outlook items. It is fired before an item (which is an instance of the parent object) is deleted.
    • The BeforeItemMove event of the Folder class. It is fired when an item is about to be moved or deleted from a folder, either as a result of user action or through program code.

    Both events allow to cancel the cation. You just need to set the Cancel parameter to true.

    Be aware, when a user deletes an Outlook item, it is moved to the Deleted Items folder. But the user can use the Shift + Delete buttons to remove the item completely without moving to the Deleted Items folder. In that case none of the event will be fired. You need to handle keybord shortcuts in that case. See Using shortcut keys to call a function in an Office Add-in for more information.