To select a file, the Net Framework provides the OpenFileDialog component.
You can see the reference at MSDN here
But basically, all you have to do is:
Create an Instance of OpenFileDialog
using(OpenFileDialog openFileDialog1 = new OpenFileDialog())
{
Set the initial property
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
Open the control calling the ShowDialog, wait for the OK press from the user and grab the file selected
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
string fileSelected = openFileDialog1.FileName;
}
}
Notice the using statement around the OpenFileDialog(), while not strictly necessary this will assure the Disposing of the dialog