.net windows api:获取或设置文件打开对话框使用的最近目录
有没有办法设置或获取 vista 文件打开对话框使用的初始目录,而无需在文件打开对话框上设置 InitialDirectory 属性?
我希望我的 WPF(在启动时)为所有打开/保存对话框设置一次默认文件夹。如果您注意到,在 Vista 中,只要计算机正在运行,它就会继续默认/跟踪用户从任何文件打开/另存为对话框中最后选择的目录。记事本或任何程序都是这样操作的。
我尝试实现此目标的原因是因为我不想在我的应用程序中跟踪它、设置和保存文件夹。我只想设置默认值,然后让 vista 跟踪它。
Directory.SetCurrentDirectory 不执行此操作。
Is there a way to set or get the initial directory used by the vista file open dialog without setting the InitialDirectory property on the file open dialog?
I want my WPF to (on startup) set the default folder once for all the Open/Save dialogs. If you notice in Vista as long as the machine is running it continues to default/track the user's last selected directory from any file open/save as dialogs. Notepad or any programs act this way.
The reason I am trying to accomplish this is because I don't want to have to track it within my app, setting and saving the folder. I would just like to set the default and let vista track it after that.
Directory.SetCurrentDirectory does not do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您排除了解决问题所需要做的确切事情。如果您未设置 InitialDirectory,则对话框将使用上次使用的目录。此信息存储在注册表中,按进程名称索引。您无法有选择地关闭此行为。
Windows 版本之间使用的注册表项一直在变化。我认为在 Win7 上它现在是 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRU。它不再像早期版本那样采用明文形式。如果您想冒险尝试解析此处列出的键值,请务必验证 Windows 版本。坦率地说,这不值得您必须编写简单的代码来初始化 InitialDirectory 属性。
You are excluding the exact thing you have to do to solve your problem. If you don't set InitialDirectory then the dialog uses the last used directory. This info is stored in the registry, indexed by process name. You cannot selectively turn this behavior off.
The registry key that's used has been changing between Windows version. I think on Win7 it is now HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\LastVisitedPidlMRU. It is no longer in cleartext like it used to be on earlier versions. If you want to risk trying to parse the key values listed there then do make sure you verify the Windows version. Frankly, this isn't worth the simple code you'd have to write to initialize the InitialDirectory property.
如果您不想编写代码来继续加载和保存 OpenFileDialog 的目录,请编写一个执行此操作的包装函数,然后只需调用您的包装函数...
If you don't want to have to write code to keep loading and saving the directory for OpenFileDialog, write a wrapper function which does this, then just call your wrapper function...