Possible Duplicate:
File being used by another process after using File.Create()
I have a method that will append text to a file. Before I append the text I check if the file exists. If it does not exist I create it then carry on as shown below.
if(!File.Exists(_someFile))
File.Create(_someFile);
using (StreamWriter file = File.AppendText(_someFile))
{
file.WriteLine("some text");
}
If the file exists there is no problem. The file will be updated. If the file does not exist and it gets created an IO exception is thrown on the line with the 'using', stating that another process is using the file. I tried to use process explorer to find out what is using the file and the result is "non existent process". Does anyone know what is happening and how to solve this problem?
EDIT: Problem solved
I could not find a question about my problem on this site when I first searched. As soon as I posted my question I saw the exact problem being address in the 'related questions' on the right. Link to the solution: File being used by another process after using File.Create() Sorry for posting a duplicate. My problem is solved.