I need to create/append a text file and write some data in that. When I write the below code to my ASP.NET application, it gives the error that file is being used by another process.
if (!File.Exists(path\file))
File.CreateText(path\file);
using(StreamWriter sw = File.AppendText(Server.MapPath(path\file)))
{
sw.WriteLine("Text Data");
sw.Close();
}
You have to create a file like that in the code below and close the file after creating it..
Take a look at this example from MSDN.
This will show you to how you can create a text file.
OR, you can create a text file in this way; The code below is from MSDN