Load txt file through a list c #

3

I make a query in the database and put it in a list, then I scan each list item through foreach to query other tables according to the Id of each line covered. If found, I would like to load a txt file for each line queried by jumping inside the file txt .

EX:

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

What I can not do is delimit the total length of the line because it has to be fixed. I'm doing 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 one row from the list, the second query can have 5 rows and should be populated. Then the  third because it has 2 lines and should be recorded, there it colts the main list and it makes the consultation again and so on. The size would be 832 columns.

    
asked by anonymous 19.11.2015 / 14:26

1 answer

1

Add a AppendLine at the end

sb.AppendFormat("{0}{1}{2}",
                     idRegistro = "1",
                     numeroControle = "          ",
                     folhaRecebe ="uuuuu")
  .AppendLine();
    
22.11.2015 / 01:36