-
October 28th, 2009, 10:25 PM
#1
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.
-
October 28th, 2009, 10:26 PM
#2
Re: Using Win Explorer to choose a path
in case that was unclear, my question is "how can i do that?"
-
October 28th, 2009, 11:11 PM
#3
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;
}
-
October 28th, 2009, 11:26 PM
#4
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).
-
October 29th, 2009, 06:18 AM
#5
Re: Using Win Explorer to choose a path
Thanks a lot vcdebugger! It's much appreciated
-
October 29th, 2009, 11:49 PM
#6
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|