OpenFileDialog fails in Win7

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

OpenFileDialog fails in Win7

Steve Green
This post has NOT been accepted by the mailing list yet.
My installer needs to open a file browse dialog. As there is no file browse dialog provided by WIX I have written a C# dll containing a method to invoke the standard OpenFileDialog when called by a Custom Action. However while this works fine in Win2003 the Custom Action just hangs when run on Windows 7. It seems to get as far as the ShowDialog() call then stop. As a test I have written a separate Windows Forms app with a single dialog and button to invoke the OpenFileDialog and, as expected, that works fine. I just can't get the OpenFileDialog to appear from within my msi!

I suspect it may be a security thing so I ran the installer from msiexec opened as Administrator but with no difference!

Does anyone have any ideas how to fix this?

Many Thanks.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: OpenFileDialog fails in Win7

Nick Ramirez
WiX does offer up a browse dialog control called DirectoryList. It's often paired up with a PathEdit control to display the path you've selected, a button to navigate up one directory (PushButton control that publishes the DirectoryListUp event), a button to create a new folder (PushButton that publishes DirectoryListNew), and an "OK" button that sets the path to a WiX Directory (PushButton that publishes SetTargetPath).

The WiX toolset has such a dialog in its Mondo set. It calls it BrowseDlg.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: OpenFileDialog fails in Win7

Steve Green
Thanks for the reply Nick. I tried the BrowseDlg but it only goes down to directory level and doesn't allow you to select individual files.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: OpenFileDialog fails in Win7

MikeR
In reply to this post by Steve Green
I ran into this same problem when trying to use OpenFileDialog().  You need to make a new thread with a different appartment type for the UI to show.  Here is a sample of what I did to make it work.

  // create a new thread with appropriate apartment state to launch UI
  FileBrowser fileBrowser = new FileBrowser(session);
  Thread worker = new Thread(fileBrowser.Show);
  worker.SetApartmentState(ApartmentState.STA);
  worker.Start();
  worker.Join();

Then implement your code in the FileBrowser class displaying the OpenFileDialog using the Show method.

-Mike
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: OpenFileDialog fails in Win7

Steve Green
That's great Mike, thanks, I'll give it a go.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: OpenFileDialog fails in Win7

Steve Green
In reply to this post by MikeR
IT WORKS!! I have to do a little tidying up and add the code to set my WIX property with the selected file but the dialog now appears!

Thanks very much for your help Mike, I think I may be able to finish the week on a high after all!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: OpenFileDialog fails in Win7

hiran536
This post has NOT been accepted by the mailing list yet.
In reply to this post by MikeR
Hi,

It works fine, but the only issue is that the OpenFileDialog dosent open on top of the installer instead it stays background. Does anyone know how to get it to focus?

Regards
Loading...