saving Outlook toolbar settings

N

Nikolas

Hi,

I developed an Outlook Addin using VS 2005 with VSTO SE in C#. Using the new
installed templates it creates a ThisAddIn.cs file with ThisAddIn_Startup()
and ThisAddIn_Shutdown() functions.

I create a custom outlook toolbar and my aim is to save its settings
(position, visibility etc.). However, if I try save the toolbars settings in
the ThisAddIn_Shutdown() function my toolbar has already been disposed. Is
there another location where I can call my SaveSettings() function where my
custom toolbar has not been yet disposed while shutting down outlook?

Thanks in advance.
 
K

Ken Slovak - [MVP - Outlook]

Explorer toolbar positions should be saved in the Explorer.Close event
handler, anything else is too late.

Remember though that two addins jockeying for the same position will end up
with one losing and the load order of multiple addins is non-deterministic.
So some other addin may steal your position. Also, many addins don't bother
saving position and may end up in your selected position if they somehow end
up there before you. Not much you can do about it, just follow the rules and
hope for the best :)
 
N

Nikolas

Thanks for the quick reply.

Outlook.Explorer doesn't seem to have a Close event in order for me to
implement it. It only has a Close() function.

Am I doing anything stupid?
 
K

Ken Slovak - [MVP - Outlook]

In C# any overloaded methods that also have an event named the same must be
handled using a separate class. Something like this:

private Outlook.ExplorerClass _ExplorerClass = null;
private Outlook.Explorer _Explorer = null;

// in an initialization procedure, after setting Explorer object
_ExplorerClass = (Outlook.ExplorerClass)_Explorer;
_ExplorerClass.ExplorerEvents_Event_Close += new
Outlook.ExplorerEvents_CloseEventHandler(_Explorer_Close);

//event handler
private void _Explorer_Close()
{
}
 
N

Nikolas

Thanks for the solution. It worked fine, however, it actually calls the
Explorer.Close event two times (before the ThisAddIn_Shutdown event) when the
Outlook applications closes down. The second time my toolbar has been
disposed and accessing its settings causes an exception.
 
K

Ken Slovak - [MVP - Outlook]

Explorer.Close should only be called once.

Are you removing the event handler in the Close code, and releasing any
Explorer related objects for that Explorer at that point?

I don't know if you're using an Explorer wrapper class to track more than 1
open Explorer, if not you should be. There's a C# code sample for that at
www.outlookcode.com. That Web site also has an example Inspector wrapper in
C#, which also should be used if you're monitoring anything Inspector
related.
 
N

Nikolas

Thanks a lot for your help.

Ken Slovak - said:
Explorer.Close should only be called once.

Are you removing the event handler in the Close code, and releasing any
Explorer related objects for that Explorer at that point?

I don't know if you're using an Explorer wrapper class to track more than 1
open Explorer, if not you should be. There's a C# code sample for that at
www.outlookcode.com. That Web site also has an example Inspector wrapper in
C#, which also should be used if you're monitoring anything Inspector
related.
 
E

enric

Hi,
I have strange behavior with the close event.

I'm using an Explorer wrapper class to track the Explorers, and for each one i suscribe the close event.

But when i close an explorer, the event was never fired. I tried with other event like Deactivate and it work fine.

Could you help me to know what happen on clode event


here part of code :

public ExplorerWrapper(Outlook.Explorer explorer)
{
..
..
..
_Explorer = explorer as Outlook.ExplorerClass;
if (_Explorer != null)
{
_Explorer.ExplorerEvents_Event_Close += new Microsoft.Office.Interop.Outlook.ExplorerEvents_CloseEventHandler(_Explorer_ExplorerEvents_Event_Close);

}
..
..
..

}


void _Explorer_ExplorerEvents_Event_Close()
{
..
..
..
}

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top