I have the following code, and I’m getting an IOException error. It says it is in use by a different process. I do not have the file opened somewhere, the application creates the file.
This is my code:
In function one:
System.IO.StreamWriter data = new System.IO.StreamWriter(@"c:\temp.txt");
data.WriteLine(temp);
data.Close()
after this, a second function is called which should process the temp file. The lines which do something with the IO are these:
string[] part = System.IO.File.ReadAllLines(@"c:\temp.txt");
in this function the string[] part is modified and added to a final complete file:
System.IO.File.AppendAllLines(Datas.Core.outputDir + @"\" + Datas.Core.outputName + ".txt", part);
I guess the System.IO.ReadAllLines function keeps the file busy, how can I change my code so I can access the file again?
You need to call
data.Dispose()(not justClose) in order to completely release the file handle.