为打开文件对话框中设置默认文件夹 [英] Setting default folder for openfile dialog
问题描述
我有一个打开文件对话框
,我试图设置默认文件夹。起初,我不得不将其设置为 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;
您使用的是 @\\ ......
。无论是摆脱@或修改 \\
到 \
。
或者,尝试:
<$p$p><$c$c>Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),"new_folder2")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")
这篇关于为打开文件对话框中设置默认文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!