The Add In
I have written a VSTO Add-In for Outlook. The crux of the add-in is to put a button on the Ribbon when a user is replying to email that will allow them to quickly set the Email Sensitivity to Confidential or back to Normal. Currently the process to do this on an email is multiple steps, and my client wants it to be one click. The button icon is Red or Green based on the sensitivity of the current email.
Sensitivity = Normal => Red Button
Sensitivity = Confidential => Green Button
There are a few basic use cases I have uncovered:
A user Creates a new Email
In this case the button should start Red and change when clicked.
A user Creates a reply to an email
In this case the button should start the same color as the parent email. If the parent email was Red, the button should be Red and if it was Green the button should be Green
A user Edits a draft
If the user has a draft the button should reflect the value of the Sensitivity property of the saved draft.
The way I chose to accomplish this was with two buttons in a ribbon XML where I override the getVisible property and based on the current MailItem set the appropriate button visible. Another way would have been to have one button and toggle the image and functionality based on MailItem sensitivity property.
Regardless of my choice I think I would have run into the same problem in that the Office Ribbon is meant to be a static object, drawn once at creation of the Explorer or Inspector and you need to force a redraw by calling the InvalidateUI method.
With that in mind, to cover my 3 use cases above I had to hook into some events from the application.
I'm not sure I can post the exact code, but the basics of it are as follows:
On Startup subscribe to:
Application.ActiveExplorer().SelectionChange
Application.Inspectors.NewInspector
On SelectionChange
If there is one item selected, and that one item is a MailItem
Refresh the Ribbon UI - Call Ribbon.InvalidateUI();
On NewInspector
If the Inspector.CurrentItem is a MailItem
Refresh the Ribbon UI - Call Ribbon.InvalidateUI();
The SelectionChange event handler covers if a user is clicking around in Outlook 2013 and up and selects an Inline Draft. It will draw the ribbon in the TabSet TabComposeTools, TabMessage. This places the icon on the main outlook window Ribbon when necessary.
The NewInspector event handler covers if the user double clicks on the draft, creating a new window.
The Problem
I have been receiving reports of Outlook crashing. At first I had limited logging and relied on the Event Logs generated by Outlook. Not very helpful.
Then I implemented log4Net, and I'm writing to a log file in the AppData folder of the user's profile. This has given me some insight
I have wrapped a try/catch around every method code block, so nothing in my add-in (that I wrote) runs outside of a try/catch, and each block just catches Exception, logs it, and throws it. This is an attempt to find the problem.
My latest log shows the UI refreshing, so it called my GetVisibility override, in there based on if the control.Context is an Explorer or Inspector I get the ActiveInlineResponse or CurrentItem as a MailItem, read the Sensitivity property and based on that return True or False if the button calling the handler should be visible. (I have one handler for both buttons)
The crash appears to happen when I am casting an ActiveInlineResponse to a MailItem. The next item in my log is the logging I do in the Startup handler of the Addin. (So the user restarted Outlook)
Other Details
The user base is currently running Outlook 2010 - Outlook 2016.
We have one add-in that runs on all of them as nothing we are doing should be specific to any version of office.
The add-in works without fail on Outlook 2010.
The add-in project selected was Outlook 2013-2016.
I'm using Ribbon XML over Designer because Designer doesn't support putting buttons in TabSets.
Update
I have put in some event handler local variables to my Add-In class as described by https://www.experts-exchange.com/questions/27305112/Problem-with-VSTO-event-handler-going-out-of-scope-in-Outlook-AddIn.html I haven't seen the error since, but also haven't had much feedback as I did this on a Friday and this Monday is a holiday. I'll update with an answer if this appears to be a "Fix".
Related
I've got an Application Level VSTO Add-In for Office 2013/2016. I need to set the active document into Draft mode.
I'm using the DocumentChange and it works fine as long as documents are opened from Word.
When a document is opened from SharePoint from a library that has Checkin/Checkout enable, it first opens Word in a minimal view:
The DocumentChange fires, but as soon as the user clicks Check Out the document goes back into normal view mode.
So, I need to either hook up to a "Check Out" event, or to an event when the Ribbon visibility is being updated. I couldn't find either. Is there an event I can use?
Is there an easy way to disable , hide and capture the event of click of outlook mail send button ? The solution has to be compatible with outlook 2007 and 2010 versions. Code examples will be appreciated.
Thanks.
You can handle the Send event of the MailItem class which is fired when the user selects the Send action for an item. Also you may find the ItemSend event of the Application class helpful. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program.
To disable or hide the button you may consider using a form region which can override the whole inspector region leaving the ribbon control intact (the Replace-all region type). See Creating Outlook Form Regions for more information. Also you may consider using Advanced Outlook view and form regions.
I want to add a form with a submit button in it in an outlook mail which I could send to a group. Once user clicks on submit button, I want data in the form to be saved in my database. Any idea how to do?
It looks like you need to develop an Outlook add-in with a form region where you can place all your custom controls for dealing with a Db. See Walkthrough: Creating Your First Application-Level Add-in for Outlook to get started quickly. The Creating Outlook Form Regions section in MSDN provides all the required information about form regions.
You can repurpose button controls on the ribbon in Outlook. See Temporarily Repurpose Commands on the Office Fluent Ribbon. But the Send button is not located on the ribbon in Outlook inspectors. You need to handle the Send event of Outlook items instead.
Also you may consider handling the ItemSend event of the Application class. It is fired whenever an Microsoft Outlook item is sent, either by the user through an Inspector (before the inspector is closed, but after the user clicks the Send button) or when the Send method for an Outlook item, such as MailItem, is used in a program.
i am developing an Outlook AddIn for Outlook 2010 with VS 2010.
When the user opens some Mails, and he changes the focus from one mailitem to another: Is there any event which can give me the currently displayed/focused mailitem?
It looks like you are interested in the SelectionChange event of the Explorer class. It is fired when the user selects a different or additional Microsoft Outlook item programmatically or by interacting with the user interface.
If you switch between inspectors, you need to handle the Activate event of the Inspector class. It is fired when an inspector becomes the active window, either as a result of user action or through program code.
I am working on an add-in for Enterprise Architect in C# that involves tabs. Tabs as in, what there is on the bottom of the screen just as in an excel sheet. For example, if you as a user would click on one of the tabs in excel the view will change to this newly clicked tab.
In the above picture, the tab "web interface" is currently selected. Now what happens in the code when the user clicks on one of the other tabs. Lets say the user clicks on "Program on user PC".
My question addresses anyone who has any Enterprise Architect Add-In developing experience. I would like to catch the mouseclick event that is fired as soon as the user clicks on one of the tabs such that I can respond properly on this event and prepare the view for the user.
I hope it is clear what I am trying to achieve. Thanks in advance!
EA does not make raw Windows input events (keyboard, mouse) available to Add-Ins, but the Context Item event EA_OnTabChanged() tells you when the user switches tabs. This sounds like what you're after.
The event includes the name of the tab being switched to, so you just need to match that to know if the event is for you.