1
I’m trying to make a replica of the notepad, in the part of saving content in richTextBox1.Text I’m having the problem:
System.IO.Ioexception:"Process cannot access file 'file path' because it is already being used by another process.
private void salvarComoToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFileDialog fileDialog = new SaveFileDialog();
fileDialog.Filter = "|*.txt";
fileDialog.ShowDialog();
fileDialog.OpenFile();
string path = fileDialog.FileName;
fileDialog.Dispose();
richTextBox1.SaveFile(path);
}
Post the code you use to open the text file
– Jéf Bueno
In case I haven’t done yet to open, just wanted to save msm. Then I would do the rest
– Jean Simas
But to make this mistake you have to be with some stream of the open file. Surely there’s more code there. There’s no helping you without seeing the troublesome part.
– Jéf Bueno
The rest is just Empty Event.
– Jean Simas
You are opening the file
fileDialog.OpenFile();
and does not close so it remains open. triesfileDialog.Close()
; before theDispose()
– JcSaint
You are opening the file with
fileDialog.OpenFile();
for no reason whatsoever in that function, and it is not closing it, hence the error. ThefileDialog.Dispose();
does not close the file.– Christian Beregula