Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I currently am writing a lightweight and flexible program to view and possibly edit pictures. Everything is going smoothly, but I've run into a roadblock. The RootFolder property of a FolderBrowserDialog control is of the Environment.SpecialFolder type, which is an enum. Due to this nature, I can't set its value as a string. How can I use the SelectedPath property of the FolderBrowserDialog to set the RootPath property for a FolderBrowserDialog?

(Note: The FolderBrowserDialog is for selecting the default folder for opening images from)
Posted
Comments
LanFanNinja 30-Nov-11 16:31pm    
In addition to the below solutions if you are wanting to restore your folder browser dialog to the last selected path when it reopens just save the value of SelectedPath when the OK button of folderBrowserDialog is clicked and then right before you call ShowDialog() again just reassign the value. i.e.

something like this

if (lastPath != "")
{
folderBrowserDialog1.SelectedPath = lastPath;
}
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
lastPath = folderBrowserDialog1.SelectedPath;
}

** lastPath being a string you have defined somewhere.

Try using Environment.SpecialFolder.MyComputer, set the SelectedPath, and then call ShowDialog(). I did the following and it worked fine:

C#
FolderBrowserDialog dlg = new FolderBrowserDialog();
dlg.RootFolder = Environment.SpecialFolder.MyComputer;
dlg.SelectedPath = @"d:\dev";
dlg.ShowDialog();
 
Share this answer
 
v3
Comments
LanFanNinja 30-Nov-11 16:24pm    
+5
Amir Mahfoozi 3-Dec-11 7:33am    
+5
Hi,

I think you need to take a look at: Environment.GetFolderPath(Environment.SpecialFolder).
If you feed the result of this call to the FolderBrowserDialog you should be OK.

for more detail info on the GetFolderPath: http://msdn.microsoft.com/en-us/library/14tx8hby.aspx[^]


Cheers, AT
 
Share this answer
 
v2
Comments
LanFanNinja 30-Nov-11 16:43pm    
+5

Edit: Fixed link

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900