为打开文件对话框中设置默认文件夹文件夹、文件、对话框中

2023-09-05 23:01:03 作者:叼着奶瓶逛青楼

我有一个打开文件对话框,我试图设置默认文件夹。起初,我不得不将其设置为 Environment.GetFolderPath(Environment.SpecialFolder.Personal)+ @\\ new_folder1和运作良好。但是我把它改为 Environment.GetFolderPath(Environment.SpecialFolder.Personal)+ @\\ new_folder2,它仍然弹出的new_folder1。当我调试它,该对话框的 InitialDirectory 是new_folder2。我删除new_folder1,但是对话仍在寻找它时,它启动。现在有没有引用任何地方在我的code到new_folder1。

任何想法可能发生的事?

编辑:这是code,我建立了我最初的打开文件对话框

 打开文件对话框DLG =新的OpenFileDialog();
 dlg.Filter =XML文件(*的.xml)| *的.xml;
 字符串pathDefault = Environment.GetFolderPath(Environment.SpecialFolder.Personal)+ @\\ new_folder2;
 dlg.InitialDirectory = pathDefault;
 

解决方案

您使用的是 @\\ ......。无论是摆脱@或修改 \\ \

或者,尝试:

Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),"new_folder2") 桌面备忘录下载 DeskNote桌面备忘录 2.2

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")