I need to create a text file with header.
Currently i’m using StreamWriter to create the txt file if it’s not available, but I need a header to be written in only once, as everytime I call this method I would write a new line into the .txt file
Below is my code:
string line = userID + "\t" + fullname + "\t" + module + "\t" +
datetime + "\t" + SQLStatement;
string fileExcel, filePath, fileName;
fileExcel = "Audit.txt";
filePath = HttpContext.Current.Server.MapPath("~");
fileName = filePath + "\\" + fileExcel;
System.IO.StreamWriter file = new System.IO.StreamWriter(fileName, true);
file.WriteLine(line);
file.Close();
1 Answer