2
I’m trying to generate a file .txt
from a code list recovered from the database. However, when the file is generated, line breaks come out in excessive number, as shown below:
The code is as below, being a foreach that traverses the entire list of objects recovered from the database and writes each code in the file . txt:
using (StreamWriter linha = System.IO.File.CreateText(caminhoArquivo))
foreach(var item in codigos)
{
linha.Write(item + "\r\n");
}
return File(caminhoArquivo, "text/plain", nomeArquivo);
For line breaking, beyond the "\r\n"
, I have tried using line.Writeline(item) and line.**Write**(item + *Enviroment.NewLine*)
, and other variations. however, the problem persisted.
Does anyone know how I solve the same?
The problem seems to be in the content, must be full of items with nothing in
codigos
.– Maniero
makes an if to check if the item is not empty before printing it
– Washington da costa
Or use the
item.Trim()
before he.– CypherPotato