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.
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.
Loading

Sam HobbsPosted Sep 6, 2010, 3:19 PM
R JPosted Sep 6, 2010, 9:16 AM
If the user wants to select folder only, then we can write code using openFolderDialog. or If user wants to select single or multiple files we can write code using openFileDialog.
But in my application the user should able to select either file or folder through a single browse button. please suggest me how to write code for this.
thank you
ShankeyPosted Sep 6, 2010, 8:48 AM
See openfiledialog only allows to select one or multiple file. It does not allow you to select folder. You can use folderbrowserdialog to select a path. But following code will allow you to get file name and selected folder. But dont forget to mark my answer as accepted if it help you a littel :)
Here is your code:
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
// below will get selected folder from openfiledialog.
textBox2.Text =openFileDialog1.FileName.Substring(0,openFileDialog1.FileName.LastIndexOf("\\"));
// below will get selected folder from folderbrowserdialog.
if(folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox3.Text=folderBrowserDialog1.SelectedPath;
}