-2

I'm trying to partition a file in 12.000 lines, using Filehelpers (3.0.39.0). Below follows my code:

       'Busca informações do Discador
        Dim dtDiscadores As New DataTable
        mensagemErro += ItauACCRepositorio.GetDiscadores(dtDiscadores, dtInicial, dtFinal)

        'DataTable->List
        Dim records = (From row In dtDiscadores.Rows
                       Select New ItauACCLayout.RetornoAcionamentoDiscador With {.DescricaoLinha = row("DCRLINHARQ")}).ToList()

        'Inicializa o motor do FileHelpers
        Dim engine As New FileHelperEngine(Of ItauACCLayout.RetornoAcionamentoDiscador)(Encoding.GetEncoding("iso-8859-1"))

        'Escreve o arquivo
        engine.WriteFile(String.Concat(_camArquivo, _nomArquivo, _extArquivo), records)

If my datatable (dtDiscadores) return more than 12.000 lines, i need to partition into 'N' files diferents!

cfasilva
  • 3
  • 4

1 Answers1

0

You can just batch your records using the batch extension from MoreLinq.

 var batches = records.Batch(12000);
 var i = 0;
 foreach(var batch in batches)
 {
     i++;
     engine.WriteFile(String.Concat(_camArquivo, _nomArquivo + i.ToString(), _extArquivo), batch);
 }
shamp00
  • 11,106
  • 4
  • 38
  • 81
  • Thank you very much @shamp00, but exists MoreLinq's Batch for VB.Net? – cfasilva Jun 02 '15 at 19:15
  • I don't know all that much about VB.NET but maybe you can use a converter [like Telerik's](http://converter.telerik.com/). Or there are various other implementations [like this one](http://www.obelink.com/Blog/PostId/9/LoopInBatchesTroughAnIEnumerable#.VW4w3M9Viko) – shamp00 Jun 02 '15 at 22:41
  • 1
    Really Skip().Take() strategy helped me! Thank you very much! – cfasilva Jun 10 '15 at 17:05
  • The `Skip().Take()` approach is less efficient than MoreLinq's batch. With say a million lines, it will spend a lot of time doing `Skip()` (at least with most Linq providers). – shamp00 Jun 11 '15 at 13:28