开发者

C# OpenFileDialog Stored Paths

开发者 https://www.devze.com 2023-01-06 10:33 出处:网络
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 gene开发者_开发百科rally the same between runs.

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 gene开发者_开发百科rally 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消