I am trying to make a try catch that will check if the file in filelocation exists or not. If it doesnt i want the open file dialog to open and allow user to be able choose the text file (and only a text file) and read the file location of the selected file and use that as the file location sting for the sream reader
any time i use this the file location will be right until the end. instead of the file name it will have bin/debug/ok
try
{
if (!File.Exists(filelocation))
{
throw new FileNotFoundException();
}
else
{
StreamReader question = new StreamReader(filelocation);
}
}
catch (System.IO.FileNotFoundException)
{
MessageBox.Show("File containing the questions not found");
OpenFileDialog OFD = new OpenFileDialog();
DialogResult result = OFD.ShowDialog();
string filelocation = result.ToString();
StreamReader question = new StreamReader(filelocation);
}