问题
I have a OpenFileDialog
and I am trying to set the default folder. Initially I had it set to Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\\new_folder1"
and that worked well. However I changed it to Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\\new_folder2"
and it still pops up in new_folder1. When I debug it, the dialog's InitialDirectory
is new_folder2. I deleted new_folder1, but the dialog still looks for it when it starts up. There are now no references anywhere in my code to new_folder1.
Any ideas as to what might be happening?
Edit: Here is the code where I set up my initial OpenFileDialog
:
OpenFileDialog dlg = new OpenFileDialog();
dlg.Filter = "XML files (*.xml)|*.xml";
String pathDefault = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + @"\\new_folder2";
dlg.InitialDirectory = pathDefault;
回答1:
You're using @"\\...."
. Either get rid of the @ or change the \\
to \
.
Or, try:
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),"new_folder2")
来源:https://stackoverflow.com/questions/14884484/setting-default-folder-for-openfile-dialog