-
April 4th, 2013, 04:15 AM
#1
Selecting a folder using a dialog box
Hi
I am trying to open a dialog box so that I would be able to select a folder so that I will return the filenames in that folder. I was trying to do this using the openfiledialog but my problem is that when I am on the folder I want to select, I can only select open to get to the files. Is there a similar dialog where it allows me to select a folder to take its path rather than open it. The following is the code i have used so far:
Code:
private void button1_Click(object sender, EventArgs e)
{
string[] filepaths;
string path;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
path = Path.GetDirectoryName(openFileDialog1.FileName);
filepaths = Directory.GetFiles(path);
textBox1.Text = path;
}
}
Thank you in advance.
-
April 4th, 2013, 12:16 PM
#2
Re: Selecting a folder using a dialog box
See FolderBrowserDialog class in msdn.
-
April 5th, 2013, 03:36 AM
#3
Re: Selecting a folder using a dialog box
Hi
Thank you very much for your reply. I managed to solve my problem using your suggestion. By any chance is there a way to make the FolderBrowseDialog look like the OpenDialog?
Once again thank you.
Regards
-
April 9th, 2013, 04:45 AM
#4
Re: Selecting a folder using a dialog box
some Sample
FolderBrowseDialog fbd = new folderBrowseDialog();
string path = null;
if(DialogResult.OK == fbd.ShowDialog())
{
// Select directory
path = fbd.SelectedPath;
// get files
if (Directory.Exists(fbd.SelectedPath))
{
foreach (string filesName in Directory.GetFiles(fbd.SelectedPath))
{
// Todo something with avaliable files in select directory
}
}
}
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
|