Hi..
i have question how to make browse button in Windowsformapplication?
i mean browse button like in web app.
after that how i can read XML file with this browse button?
thanks.
How to make browse button
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Posted Jun 20, 2012, 8:02 PM EDT
On click of a button, you can call FileOpenDialog.ShowDialog() to show the window where the user can select the xml file.
You can apply the filter to show only the xml files.
dialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
Once the file is selected, you can use FileOpenDialog.FileName property to get the selected filename.
Use xmltextreader to read the xml file.
Form load event:
FileOpenDialog fileOpenDialog = new FileOpenDialog();
Button Click event :
fileOpenDialog.Filter = "xml files (*.xml)|*.xml|All files (*.*)|*.*";
fileOpenDialog.ShowDialog();
XmlTextReader xmltextReader = null;
if (fileOpenDialog.ShowDialog() == DialogResult.OK)
{
xmltextReader = new XmlTextReader(fileOpenDialog.FileName);
//you continue the xml processing....
}
Hope this helps you.
Satyapriya NayakRank #47 · 31.5K reputationPosted Jun 20, 2012, 8:03 PM EDT
Try this...
private void btnbrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openfiledialog1 = new OpenFileDialog();
openfiledialog1.ShowDialog();
openfiledialog1.Filter = "allfiles|*.xml";
TextBox1.Text = openfiledialog1.FileName;
}
Thanks