Initial directory for OpenFileDialog vs FolderBrowserDialog

497 views Asked by At

When I use the OpenFileDialog to pick a file, it remembers the last visited directory so that when I go back to the dialog, it starts in that location by default.

But the FolderBrowserDialog does not start at that location and instead starts at the specified RootFolder.

So I would like to know where does OpenFileDialog store the last visited path so I can retrieve it and use it as the default location for FolderBrowserDialog.

2

There are 2 answers

0
Alexander Bell On

First, make sure that the property RestoreDirectory of the OpenFileDialog is set to false. Then you can check the value of Environment.CurrentDirectory to get the most recent one. Hope this may help.

0
NoviceProgrammer On

If you need to set the top-most folder that will appear within the tree view of the dialog box, set the RootFolder property, which takes a member of the Environment.SpecialFolder enumeration.

So the only way to keep the last used directory is to set the SelectedPath property yourself. Store the last selected directory by the user in a field/configuration settings and then restore it before opening the FolderBrowserDialog