I have a FolderBrowserDialog, displayed with code shown below. However, it keeps opening with 'Computer', i.e. the root of the folder tree, selected. How do I get it to open on the selected folder?
var folderBrowser = new FolderBrowserDialog(); folderBrowser.Description = "Select Chase 6 Installation Folder"; folderBrowser.RootFolder = Environment.SpecialFolder.MyComputer; folderBrowser.ShowNewFolderButton = false; if (Directory.Exists(Properties.Settings.Default.defaultChasePath)) { string x = Properties.Settings.Default.defaultChasePath; folderBrowser.SelectedPath = x; } if (folderBrowser.ShowDialog(this) == DialogResult.OK) { chasePathtext.Text = folderBrowser.SelectedPath; }
Once the ShowDialog method is called, you can browse and select a file. SelectedPath property represents the selected path in a FolderBrowserDialog control. RootFolder property represents the root folder from where the browsing starts.
If you set RootFolder to Environment.SpecialFolder.Desktop then it will open to the SelectedFolder as long as the path is valid.
When you set RootFolder to Environment.SpecialFolder.MyComputer, then the first time the dialog opens, it will always start at MyComputer, not the SelectedFolder path.
If a valid selection is made, then subsequent uses of the same FolderBrowserDialog instance will open at the previously selected path.
From the Microsoft help for FolderBrowserDialog class:
Typically, after creating a new FolderBrowserDialog, you set the RootFolder to the location from which to start browsing. Optionally, you can set the SelectedPath to an absolute path of a subfolder of RootFolder that will initially be selected.
Are you possibly setting the SelectedPath to a location that doesn't equate to a subfolder of RootFolder (i.e. My Computer)? That would probably cause it to dive back to the RootFolder as the presented location.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With