Load txt file through a c# list

Question:

I do a query in the database and put it in a list, then scan each item in the list through foreach to query other tables according to the Id of each row traversed. If found, I would like to load a txt file for each line consulted, jumping into the txt file.

EX:

  • maria street 3 city sao paulo
  • sidnei street 3 city Campinas

What I can't do is delimit the total length of the line as it has to be fixed. I'm doing it in C# with StringBuilder : Ex:

 StringBuilder sb = new StringBuilder(); 
    foreach (var item in registros) 
    { 
        string testeID = Convert.ToString(item.Cells["ID"].Value.ToString());         
        string testecodigo = Convert.ToString(item.Cells["CODIGO"].Value.ToString());
    }


  StringBuilder sb = new StringBuilder();
            foreach (var item in registros)
            {
                 areaNaoConstaRecebe = " ";
                folhaRecebe = Convert.ToString(item.Cells["FOLHA"].Value.ToString());
                folhaRecebe = folhaRecebe.PadRight(5, ' ');
                sb.AppendFormat("{0}{1}{2}",
                 idRegistro = "1",
                 numeroControle = "          ",
                 folhaRecebe ="uuuuu",

The first query saves a row from the list, the second query can have 5 rows and must be populated. After the third, because it has 2 lines and should be recorded, then it collects the main list and makes the query again and so on. The size would be 832 columns.

Answer:

Add an AppendLine at the end

sb.AppendFormat("{0}{1}{2}",
                     idRegistro = "1",
                     numeroControle = "          ",
                     folhaRecebe ="uuuuu")
  .AppendLine();
Scroll to Top
AllEscort