Wednesday, November 2

Temporary Outlook Buttons

I have written an C# add-in to create a button on Outlook. There was a problem with this in that if you closed down outlook, then uninstall the add-in, then restarted outlook, the button was still there, but did not do anything. I had tried without success to delete the button in the OnDisconnection event handler, but found a much simpler fix:

1) Detect if the button is present in the OnConnection event handler.
2) Remove it if it is present.
3) Create a temporary button using code like this:

bool temporary = true;
this.toolbarButton = (CommandBarButton)commandBars["Standard"].Controls.Add(1, System.Reflection.Missing.Value, System.Reflection.Missing.Value, System.Reflection.Missing.Value, temporary);

The temporary button will be deleted when outlook closes. There isn't any need to do anything in any of the other event handlers in the IDTExtensibility2 interface.

No comments: