Note: I am assuming you have a form created in C#.
1) Create a Rich Text Box on the form. Right click on the box and open Properties. Under Design , change the name to: path (or whatever you want to call it)
2) Add a button to the form and name it “Browse”
3) Now double click on the button and code will open.
4) Inside the button_Click event, you want to post this code:
OpenFileDialog browseFile = new OpenFileDialog();
browseFile.Filter = "XML Files (*.xml)|*.xml";
browseFile.Title = "Browse XML file";
if (browseFile.ShowDialog() == DialogResult.Cancel)
return;
try
{
path.Text = browseFile.FileName;
}
catch (Exception)
{
MessageBox.Show("Error opening file", "File Error",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
This code is for XML File but you can change the value in the Filter for any other type of file.