??? I don't understand your code and what do you want to do with that, but normally I use it like this:
OpenFileDialog openFileDialog = new OpenFileDialog();
DialogResult dialogResult = openFileDialog.ShowDialog();
if(dialogResult == DialogResult.OK && openFileDialog.FileName != "")
{
// use something with this filename (openFileDialog.FileName)
// For example :
// FileStream fileStream = new FileStream(openFileDialog.FileName, FileMode.Open);
// ...
// fileStream.Close();
}
or
OpenFileDialog openFileDialog = new OpenFileDialog();
if(openFileDialog.ShowDialog() == DialogResult.OK)
{
System.IO.FileStream filestream = openFileDialog.OpenFile();
// ... use something with filestream
filestream.Close();
}
Before ShowDialog() you can only set the property like Path, Filter, etc... Then you must call ShowDialog() to show the dialog. If the user select a file and click OK, then you get a return value DialogResult.OK. Then you can get the filename by calling openFileDialog.FileName.