1

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.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Gilles jr Bisson
  • 449
  • 4
  • 11

2 Answers2

0

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.

Alexander Bell
  • 7,842
  • 3
  • 26
  • 42
0

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

NoviceProgrammer
  • 3,347
  • 1
  • 22
  • 32