我需要创建一个带有标题的文本文件。
目前我正在使用StreamWriter
它来创建 txt 文件,如果它不可用,但我只需要写入一次标题,因为每次调用此方法时,我都会在 .txt 文件中写入一个新行
下面是我的代码:
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();