tags:

views:

47

answers:

3
+4  Q: 

return a filename

using openFileDialog will not return a filename in use, I want the filename only I don't care if it's in use

The file will most likely be in use, I just want to be able to find the file and retrieve its name and location to perform a connection.

OpenFileDialog works until I select the file, then it has a popup that says "File in Use". I don't want it to check for that, just return the filename.

+1  A: 

I googled and found a thread that suggests this is a bug in the control:

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/56fbbf9b-31d5-4e89-be85-83d9cb1d538c/

The suggested workaround is to call the API directly as found here:

http://www.codeproject.com/KB/dialog/customize_dialog.aspx?print=true

Christopher Painter
+3  A: 

It seems that setting the ValidateNames property to false solves the problem (but don't ask why :) ...)

Here's the code I used to try out:

var f=File.OpenWrite(@"C:\test.txt");
var ofd = new OpenFileDialog();
ofd.ValidateNames = false;
ofd.ShowDialog();
f.Close();

Commenting out the third line gave me the described error "file in use".

MartinStettner
Worked for me as well. Win7
Hans Passant
+2  A: 

Try setting ValidateNames to false.

OpenFileDialog fd = new OpenFileDialog();
fd.ValidateNames = false;
JustBoo
Laughing... like dogs on steak. :-)
JustBoo