设置一个SaveFileDialog的初始目录? [英] Setting the initial directory of an SaveFileDialog?

查看:2627
本文介绍了设置一个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还有<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.filedialog.initialdirectory.aspx"><$c$c>InitialDirectory属性。

You need to set the RestoreDirectory to true as well as the InitialDirectory property.

这篇关于设置一个SaveFileDialog的初始目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆