Click here to Skip to main content
15,893,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

How can I browse both folders and files at a time?

If I use openFileDialog it can browse only files

If I use openFolderdialog it can browse folders only.

Please suggest to me how to do it or give some sample code.

.....

hi..

I have one browse button and one text box. In the browse_button click event, I would like to browse the files and place the path name into textbox. For this i'vw written code like this by using openfile dialog.

C#
private void brwsbtn_Click(object sender, EventArgs e)
        {
            if (openFD.ShowDialog() == DialogResult.OK)
            {
                  textBox1.Text = openFD.FileName;
            }
            textBox1.Text="";
        }


So that i am able to select files only. how can i select and place the folders path in textbox.
Posted
Updated 6-Sep-10 2:09am
v3
Comments
Dalek Dave 6-Sep-10 7:16am    
Edited for Grammar and Syntax.
Per Söderlund 6-Sep-10 7:33am    
This is not clear, you can browse folders with openfiledialog.
Can you give more information on this?
Toli Cuturicu 6-Sep-10 8:00am    
Correct! Use OpenFileDialog to browse both files and folders.
Ramesh Jallepalli 6-Sep-10 8:13am    
thank you.
can you suggest me how to browse and place the path names in textbox by using openFiledialog. once please read my updated question.

new System.IO.FileInfo(openFD.FileName).Directory.ToString() will give you only the path of the file.
Are you loking out for something like that?
 
Share this answer
 
Comments
Ramesh Jallepalli 6-Sep-10 8:40am    
thank you for reply..
If i selected only the folder how can i get the path into textbox. i am beginner to c sharp. plese suggest me.
//i have a code to list all files and folders
string sourcePath = sourceFolderPath//enter your folder name

int numcount = 0;
int i = 0;
int f=0;
foreach (string fl in Directory.GetFiles(sourcePath))
{
filelist[f] = fl;//all files in parent directory
f++;
}
while (sourcePath != null)
{
//get all subfolders recursively
foreach (string drs in Directory.GetDirectories(sourcePath))
{
//get all files in subdirectories

foreach (string files in Directory.GetFiles(drs))
{
filelist[f] = files;
f++;

}
directoylist[i] = drs;//sub directories


i++;
}
sourcePath = directoylist[numcount];
numcount++;
}
 
Share this answer
 

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