Setting default folder for openfile dialog

℡╲_俬逩灬. 提交于 2020-01-22 00:21:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!