I am doing a winform app right now and want to use the OpenFileDialog control. I need to open a file... but I can't. It is weird, it is painfull and makes me very said. What is happening that when the execution arrives to this line, my application just hangs:
(new System.Windows.Forms.OpenFileDialog()).ShowDialog();
Does nothing. Almost like that OpenFileDialog would be there somewhere just only not visible. I moved this line to several different places and no luck, I moved it to my main procedure and it did not work there either and I do not understand what is happening and why. If I remove this one line then my appplication is just do fine, if I put this line back it hangs.... If anyone knows the solution please tell me. The other weird thing is when I shut down the machine a nice dialog window pops up telling me that some "WindowsForms ParkingWindow" is not responding and do I want to end the process...
This is clearly the low point of the week for me!
[Update]
ofdFile.InitialDirectory = Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
if(ofdFile.ShowDialog(this) == DialogResult.OK)
{
...
}
Setting the InitialDirectory was the key thing. It works now and if I remove the InitialDirectory line it does produce the same error. However I checked some of my earlier stuff and the FileOpenDialog was called without setting the InitialDirectory property. I tried to create a test project and I could do OpenFileDialog with no InitialDirectory specified at all... Weird!