I have searched numerous web pages but I can't seem to find anywhere which shows how to stop a blank line appearing at the end of a file when using StreamWriter.
The code I've written below is the only way I can get this to work for me.. and although this works perfectly fine for the utility I am creating, I would like to know if there is a better/more efficient way to do this?
int count = 0;
int lineCount = newFile.Count;
using (System.IO.StreamWriter extract = new System.IO.StreamWriter(outputFile, true))
{
foreach (var line in newFile)
{
count++;
if (count != lineCount)
{
extract.Write(line + Environment.NewLine);
}
else
{
extract.Write(line);
}
}
}
Any thoughts people?