C# Outlook 2003 Addin

C

Craig

Hi

I created a CommandBarPopup with a couple of menu items. The Click event
handler for one of the menu items is the following code:

private void OnClick(CommandBarButton Ctrl, ref bool CancelDefault) {
OpenFileDialog ofd = new OpenFileDialog();
if(ofd.ShowDialog() == DialogResult.OK) {
MessageBox.Show(ofd.FileName);
}
}

When the event is called, the OpenFileDialog does not appear. I've made my
class derived from IWin32Window implementing the property Handle (which
returns the handle of Outlook) and passed this value into ShowDialog, but
still nothing.

Can anyone please help me with this, I'm all out of ideas...

Craig
 
K

Ken Slovak - [MVP - Outlook]

Are you sure the event is even being called? Is the object whose Click event
you're handling declared at the class or other level where it won't go out
of scope and be garbage collected?
 
C

Craig

Hi Ken

Thanks for the reply. I'm positive the event is being called, I have
several MessageBox.Show("message") calls in the event code.

Interesting enough, the message box gets displayed with and without
IWin32Window.Handle being passed into the Show(...) method. I'm at a loss as
to why OpenFileDialog doesn't.

The only work-around I can think of, is create a form that can host the
OpenFileDialog and make it appear in the Form_Load event with the form being
hidden. This is a crap work-around but I'm all out of ideas, I've even
interop'd to the Win32 native structures and calls, still nothing, ahhhh

Craig
 
K

Ken Slovak - [MVP - Outlook]

I don't know, the code you're using is pretty much right from the help
samples for OpenFileDialog, so I'm not sure why it's not working.
 

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