Click to See Complete Forum and Search --> : Using Win Explorer to choose a path
eliss93
October 28th, 2009, 10:25 PM
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.
eliss93
October 28th, 2009, 10:26 PM
in case that was unclear, my question is "how can i do that?"
vcdebugger
October 28th, 2009, 11:11 PM
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;
}
BigEd781
October 28th, 2009, 11:26 PM
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).
eliss93
October 29th, 2009, 06:18 AM
Thanks a lot vcdebugger! It's much appreciated :)
vcdebugger
October 29th, 2009, 11:49 PM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.