Set folder browser dialog start location
Is there any way to set the initial directory of a folder browser dialog to a non-special folder? This is what I'm currently using
fdbLocation.RootFolder = Environment.SpecialFolder.Desktop;
but I want to use a path I have stored in a string something like thisfdbLocation.RootFolder = myFolder;
This causes an error "Cannot convert 'string' to 'System.Environment.SpecialFolder'".
Just set the SelectedPath
property before calling ShowDialog
.
fdbLocation.SelectedPath = myFolder;
Set the SelectedPath
property before you call ShowDialog
...
folderBrowserDialog1.SelectedPath = @"c:\temp\";
folderBrowserDialog1.ShowDialog();
Will start them at C:\Temp
fldrDialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
"If the SelectedPath property is set before showing the dialog box, the folder with this path will be the selected folder, as long as SelectedPath is set to an absolute path that is a subfolder of RootFolder (or more accurately, points to a subfolder of the shell namespace represented by RootFolder)."
MSDN - SelectedPath
"The GetFolderPath method returns the locations associated with this enumeration. The locations of these folders can have different values on different operating systems, the user can change some of the locations, and the locations are localized."
Re: Desktop vs DesktopDirectory
Desktop
"The logical Desktop rather than the physical file system location."
DesktopDirectory:
"The directory used to physically store file objects on the desktop. Do not confuse this directory with the desktop folder itself, which is a virtual folder."
MSDN - Special Folder Enum
MSDN - GetFolderPath
To set the directory selected path and the retrieve the new directory:
dlgBrowseForLogDirectory.SelectedPath = m_LogDirectory;
if (dlgBrowseForLogDirectory.ShowDialog() == DialogResult.OK)
{
txtLogDirectory.Text = dlgBrowseForLogDirectory.SelectedPath;
}