private void buttonAdd_Click(object sender, EventArgs e)
{
string path = @"comics.txt";
if (!File.Exists(path))
{
var myComicsFile = File.Create(path);
myComicsFile.Close();
FileStream file = new FileStream("comics.txt", FileMode.Open, FileAccess.ReadWrite);
TextWriter write = new StreamWriter(path);
}
else if (File.Exists(path))
{
FileStream file = new FileStream("comics.txt", FileMode.Open, FileAccess.ReadWrite);
TextWriter write = new StreamWriter(path);
}
}
I keep getting the error System.IO.IOException: 'The process cannot access the file because it is being used by another process' I thought I had fixed it by closing the file after i created it the opening it but i get the error still. Not sure what the correct solution is. Any help would be greatly appreciated.