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 th开发者_Go百科at, just return the filename.
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".
Try setting ValidateNames to false.
OpenFileDialog fd = new OpenFileDialog();
fd.ValidateNames = false;
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
精彩评论