getting error while creating file if file is not exist. the error is The process cannot access the file 'c:\\temp\\file1.txt' because it is being used by another process.
i m getting error in else part at line using(streamwriter writer=new streamwriter("c:\\temp\\file1.txt",append:true))
string filename = c:\\temp\\file1.txt;
if (file.exists(filename))
{
string var1 = "fgg";
string var2 = "gg";
string print+= var1;
print += var2;
using (StreamWriter writer = new StreamWriter("c:\\temp\\file1.txt", append: true))
{
writer.writeline(print);
writer.close();
}
}
else
{
string var1 = "fgg";
string var2 = "gg";
string print+= var1;
print += var2;
using (StreamWriter writer = new StreamWriter("c:\\temp\\file1.txt", append: true))
{
writer.writeline(print);
writer.close();
}
}