Using Win Explorer to choose a path
I want the user of my window's forms app to be able to set a path, i.e. "c:\users\eli\desktop\example.txt", by have them click a button that opens windows explorer to a specified folder, wherein the user can double click one of the items in the folder to choose it (at which point the path to the chosen file would be stored into a string for later use). Really it would be just like WinRar or any of the many many other apps that let you 'explore' to find a file.
Re: Using Win Explorer to choose a path
in case that was unclear, my question is "how can i do that?"
Re: Using Win Explorer to choose a path
Code:
private StringBuilder GetSelectedFolderPath()
{
StringBuilder selectedFolderPath = new StringBuilder("C:\'Temp");
//Assign some default path
using (FolderBrowserDialog fbd = new FolderBrowserDialog())
{
fbd.SelectedPath = "C:\'Temp";
if (fbd.ShowDialog() == DialogResult.OK)
{
selectedFolderPath = new StringBuilder(fbd.SelectedPath);
}
}
return selectedFolderPath;
}
Re: Using Win Explorer to choose a path
Not sure why you would use a StringBuilder in that example. Also, you assign selectedFolderPath a value and never use it (it is wiped out by the assignment in the if statement).
Re: Using Win Explorer to choose a path
Thanks a lot vcdebugger! It's much appreciated :)
Re: Using Win Explorer to choose a path
BigEd781
I have used StringBuilder to store the selcted path - but in this case I have hardcoded 'C:/Temp" as the path or else "fbd.SelectedPath" might have the actual path selected by the user in the BrowserDialog.