I am working on a C# application, that involves creating a text file (commands.txt), filling it with some text, closing the file, and then have a different program read the file. This happens after a user fills out some information, and then clicks a button. It works great the first time. However, if the user clicks the button a second time, the program it executes (in this case, plink, a command line version of putty) says that it can't open my 'commands.txt' file. I have to exit out of the program, and re-open it in order to get it to work again.
I closed the writer, and the stream as you can see in the code below.
//create command file
string command_path = txt_plink7.Text.Replace("plink.exe", "commands.txt");
FileStream cmd_stream = new FileStream(command_path, FileMode.Create);
StreamWriter cmd_writer = new StreamWriter(cmd_stream);
cmd_writer.WriteLine("sh zoneset active | inc \"pwwn 20:|pwwn 21:\"");