设置一个SaveFileDialog的初始目录? [英] Setting the initial directory of an SaveFileDialog?
问题描述
我想一个SaveFileDialog有以下行为:
I'd like a SaveFileDialog with the following behavior:
-
第一次打开它,它关系到我的文档。
The first time you open it, it goes to "My Documents".
之后,它会到最后选择的文件夹。 什么是实现这一目标的最好方法是什么?
Afterwards, it goes to the last selected folder. What's the best way to accomplish this?
如果我没有设置InitialDirectory,它进入exe文件的目录 - 这不是我想要的。它rememebers最后选定的目录,虽然 - 甚至执行之间
If I don't set the InitialDirectory, it goes to the exe's directory - which is not what I want. It rememebers the last selected directory though - even between executions.
如果我设置了InitialDirectory,它不记得最后选定的目录。当然,我可以保存在注册表中的最后选择的目录:(但我在寻找一个更好的解决方案。
If I set the InitialDirectory, it does not remember the last selected directory. Of course, I could save the last selected directory in the registry :( but I am looking for a better solution.
SaveFileDialog dialog = new SaveFileDialog();
//??? dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
dialog.ShowDialog();
任何意见?
推荐答案
您需要设置<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.restoredirectory.aspx"><$c$c>RestoreDirectory$c$c>以真
还有<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.initialdirectory.aspx"><$c$c>InitialDirectory$c$c>属性。
You need to set the RestoreDirectory
to true
as well as the InitialDirectory
property.
这篇关于设置一个SaveFileDialog的初始目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!