Hello All
when using the following code to present a browse for file dialog to a user, sometimes the windows will open behind another windows and therefore cannot be seen. I know I have seen a tip somewhere on how to prevent this from happening (i.e. method etc) but I cannot locate it at the moment. Does someone know how to make sure the windows always opens on top?
Thanks all
Hello EBrant, yes because you have ShowHelp set to true a different form is being drawn. If you change this to false you will see that the window actually looks different. This window will popup everytime it is created.
So try the following code, I tested this on Windows 8 and Server 2008R2, both with PowerShell v3. I have also improved your function by including a param() block, fixed the incorrect bracket on the first line and removed the line break character, which you should (almost) never use:
Thanks Jaap
Ernie
Hello Jaap
Unfortunately there is a bit of a gotcha here and that is this
I am using PowerShell v2 (not sure if the same issue is present in PowerShell v3)
if you remove the line
$openFileDialog.ShowHelp = $true it works as expected when run from the ISE or PowerGUI etc, however if you run from the PowerShell console it appear to hang i.e. prompt does not return and no dialog displayed. I also tried running PowerShell in single threaded mode -sta to overcome this no cigar
So it looks like if you are running form the GUI set $openFileDialog.ShowHelp to $false and if you are running from the shell set to $true
I got around this issue by using if
if
($host.name -ne "ConsoleHost") {......}
Check it out see what you think (try in PosH 3 too), I see you posted a useful tip on the above subject (emailed), you may want to adjust slightly depending on your finding re the above.
Thanks again for your help Jaap
Jaap
Picking up on your helpful post, I just adjusted like so, now works OK in console or GUI
Great, thanks for letting us know EBrant. Thank for doing some extensive testing, PowerShell 2 is not very common in my environment anymore so I did not get around to testing it there.