You can use the OpenFileDialog class to select a file selection dialog
OpenFileDialog fileDialog= new OpenFileDialog();
fileDialog.DefaultExt = ".txt";
fileDialog.Filter = "Text documents (.txt)|*.txt";
fileDialog.ShowDialog();
To read the contents: you get the file name from OpenFileDialog and use it to perform an I / O operation.
if(fileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.StreamReader sr = new
System.IO.StreamReader(fileDialog.FileName);
MessageBox.Show(sr.ReadToEnd());
sr.Close();
}
source
share