简体   繁体   中英

Setting default folder for openfile dialog

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;

You're using @"\\\\...." . Either get rid of the @ or change the \\\\ to \\ .

Or, try:

Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),"new_folder2")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM