FileDialog.RestoreDirectory 属性实际上有什么作用?

发布于 2024-10-05 20:12:06 字数 155 浏览 5 评论 0原文

我已经在 MSDN 上阅读了有关该属性的信息,但我仍然不明白它的作用。

获取或设置一个值,指示 对话框是否恢复 关闭前的当前目录。

这究竟意味着什么? “恢复”当前目录实际上做了什么?感谢您的帮助。

I've read about the property on MSDN, but I still don't understand what it does.

Gets or sets a value indicating
whether the dialog box restores the
current directory before closing.

What exactly does that mean? What does 'restoring' the current directory actually do? Thanks for the help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

泪意 2024-10-12 20:12:06

IIRC,在 Windows XP 中,当您按 SaveFileDialog 上的 Save(或按 OpenFileDialog 上的 Open)时,该目录位于文件被保存(或打开),被设置为新的当前工作目录(Environment.CurrentDirectory 中的目录)。

通过设置FileDialog.RestoreDirectory = true,当您关闭FileDialog时,原始工作目录将被恢复。

在 Windows Vista/7 中,行为始终为 FileDialog.RestoreDirectory = true(是的,即使您将其设置为 false...)。

IIRC, in windows XP when you press Save on a SaveFileDialog (or Open on a OpenFileDialog) the directory where the file is saved (or opened), is set as the new current working directory (the one in Environment.CurrentDirectory).

By setting FileDialog.RestoreDirectory = true, when you close the FileDialog the original working directory is restored.

In Windows Vista/Seven the behavior is always as FileDialog.RestoreDirectory = true (yes, even if you set it to false...).

路弥 2024-10-12 20:12:06

原始实现的一个恼人的怪癖是,在您做出选择后应用程序的当前目录更改为该文件夹,这意味着如果您期望文件操作与您的应用程序文件夹相关,那么它现在失败了。

这意味着在使用对话框之前添加代码来捕获当前文件夹并在之后恢复它是常见的做法。

此问题已修复,因此它可以为您执行此操作,但更改默认行为可能会破坏依赖于该怪癖的代码。因此,您需要通过此属性手动启用它。

An annoyig quirk of the original implementation was that after you made your selection the current directory of your app changed to that folder, meaning that if you expected File operations to be relative to your app folder, it now failed.

This meant it was common practice to add code to capture the current folder before using he dialog, and restore it afterwards.

This was fixed, so it can do this for you, but changing the default behaviour might have broken code tha relied on the quirk. So you need to enable it manually via this property.

南城旧梦 2024-10-12 20:12:06

如果设置为 true,文件对话框将始终打开默认文件路径(InitialDirectory 属性)。

If it's set to true the file dialog will always open the default file path (InitialDirectory property).

梦忆晨望 2024-10-12 20:12:06

在这里,我仅讨论 WinForms FileDialog,WPF FileDialog 可能有不同的行为。

对于Win XP,在使用对话框期间当前目录会发生更改。

对于多线程应用程序,这一点必须要注意。通过在新线程中运行循环来检查在使用对话框期间切换到另一个文件夹时当前目录是否更改,很容易证明。

对于Win 7 / mono,使用对话框期间或之后不会更改当前目录。

因此Win 7 / mono:不需要RestoreDirectory属性。

Here, I am talking about WinForms FileDialog only, WPF FileDialog may have different behaviour.

For Win XP, the current directory is changed during the use of dialog.

For multi-threaded application, this must be aware. It is easy to proof by running a loop in a new thread to check if current directory is changed during the use of dialog, when switching to another folder.

For Win 7 / mono, the current directory is not changed during or after using the dialog.

Therefore Win 7 / mono: RestoreDirectory property is not needed.

朱染 2024-10-12 20:12:06

当您在使用对话框时可以选择目录时,下次使用该对话框时将在上次使用的目录中打开。使用此选项将恢复原始目录。

When you can select a directory when using the dialog box, next use of the dialog will open in the last used directory. Using this option will restore the original directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文