Как указано hmemcpy , ваша проблема в следующих строках
using (myStream = openFileDialog1.OpenFile())
{
string file = Path.GetFileName(openFileDialog1.FileName);
string path = Path.GetDirectoryName(file);
StreamReader reader = new StreamReader(path);
MessageBox.Show(file, "fileName");
MessageBox.Show(path, "Directory");
}
Я сломаюсь за тебя:
/*
* Opend the file selected by the user (for instance, 'C:\user\someFile.txt'),
* creating a FileStream
*/
using (myStream = openFileDialog1.OpenFile())
{
/*
* Gets the name of the the selected by the user: 'someFile.txt'
*/
string file = Path.GetFileName(openFileDialog1.FileName);
/*
* Gets the path of the above file: ''
*
* That's because the above line gets the name of the file without any path.
* If there is no path, there is nothing for the line below to return
*/
string path = Path.GetDirectoryName(file);
/*
* Try to open a reader for the above bar: Exception!
*/
StreamReader reader = new StreamReader(path);
MessageBox.Show(file, "fileName");
MessageBox.Show(path, "Directory");
}
Что вам нужно сделать, это изменить код на что-то вроде
using (myStream = openFileDialog1.OpenFile())
{
// ...
var reader = new StreamReader(myStream);
// ...
}