Replace all your logic related to the OpenFileDialog
with File.Open
:
using (var myStream = File.Open(someFilePath, FileMode.OpenOrCreate))
{
Question.PersistObject(questions, myStream); // do something with the stream
}
The OpenOrCreate
file mode will open the file if it exists, or create it if it does not.
The using
statement will take care of closing the stream for you.