I am writing a text into a file. I am getting a column from database and stored it in a string and writing it in a text file. That column contains c# code and it is writing like a single line with small squares for next line(space). I need to write it line by line. Here is my code.
using (var dest = File.AppendText(Pa开发者_StackOverflow中文版th.Combine(_logFolderPath, "a.txt")))
{
dest.WriteLine(line.TrimStart());
}
Any suggestion?
Does Notepad show small squares for new lines, but when you look at the file in Visual Studio it's OK? If so, my guess is that this will fix it:
dest.WriteLine(line.TrimStart().Replace("\n", Environment.NewLine));
try this
File.AppendAllText(Path.Combine(_logFolderPath, "a.txt",
line.Trim() + Environment.NewLine));
dest.WriteLine(line.TrimStart().Replace("\n", Environment.NewLine).Replace("\r", Environment.NewLine));
精彩评论