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.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Jun 21, 2012, 12:02 AM
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 NayakPosted Jun 21, 2012, 12:03 AM
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