C# OpenFileDialog 存储路径

发布于 2024-09-08 16:25:51 字数 410 浏览 4 评论 0原文

在我的应用程序中,我有两个地方需要用户选择文件。在这两种情况下,文件位于不同的目录中,但它们在运行之间通常是相同的。

OpenFileDialog 似乎默认为最后使用的目录,但这对我来说毫无用处,因为它几乎总是错误的文件夹,并且我最终在两个文件夹之间交替。我想要的是以某种方式让第一个对话框记住上次打开时使用的路径,第二个对话框也记住它自己的路径。

示例:路径 A 是 C:\foo\bar\something\x.dll,路径 B 是 C:\foo\baz\whatever\y.xml

对话框 a 打开,我选择 A,然后打开对话框 b(默认为 A )并且我必须向后导航到 B。 当我再次打开应用程序时,对话框 a 打开(默认为 B),我必须再次导航回 A。

我想通过单独记住路径来避免所有这些额外的导航。有没有好的方法可以做到这一点?

In my application I have two places where the user needs to select a file. In both cases, the files are in different directories, but they are generally the same between runs.

The OpenFileDialog appears to be defaulting to the last directory used, but this is useless to me since it is almost always the wrong folder, and I end up alternating between the two folders. What I would like is to somehow have the first dialog remember the path that was used the last time it was opened, and the second to remember its own path as well.

Example: Path A is C:\foo\bar\something\x.dll, Path B is C:\foo\baz\whatever\y.xml

Dialog a opens and I select A, then later dialog b opens(defaulted to A) and I have to navigate back and up to B.
When I open the app again dialog a opens (defaulted to B) and I have to navigate back up to A again.

I would like to avoid all of this extra navigation by remembering the paths separately. Is there a good way to do that?

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

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

发布评论

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

评论(1

Spring初心 2024-09-15 16:25:51

打开每个对话框时,只需设置对话框的 InitialDirectory 属性到该对话框上次使用的文件夹。

当然,这需要保存每个对话框的目录,但它将提供您想要实现的行为。

When you open each dialog, just set the dialog's InitialDirectory property to the folder that was last used for that dialog.

Granted, this will require saving the directory for each dialog, but it will provide the behavior you are looking to achieve.

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