Alternatives to Render a report as CSV file

812 Views Asked by At

I need to Render a report as CSV, but I found in some forums that LocalReport don't render CSV. I have a lot of reports in rdlc, and change it would be very hard, I think.

I thougth to Render as Excel, get the bytes and transform it to CSV, but I don't know how to do it.

Here is some code:

if (FormatoRelatorioEnum.XLS == (FormatoRelatorioEnum)formatoRelatorio){
   bytes = lr.Render("Excel", deviceInfo);
   if (temMais || parte > 1){
      nomeArquivoDownload = "Relatorio_" + relatorioModel.nomeRelatorio + "_Parte_" + parte + ".xls";
   }
   else{
      nomeArquivoDownload = "Relatorio_" + relatorioModel.nomeRelatorio + ".xls";
   }
   contentType = "application/vnd.ms-excel";
}
else if(FormatoRelatorioEnum.PDF == (FormatoRelatorioEnum)formatoRelatorio){
   bytes = lr.Render("PDF", deviceInfo);
   nomeArquivoDownload = "Relatorio_" + relatorioModel.nomeRelatorio + ".pdf";
   contentType = "application/pdf";
}
else{
   bytes = lr.Render("CSV", deviceInfo);
   nomeArquivoDownload = "Relatorio_" + relatorioModel.nomeRelatorio + ".csv";
   contentType = "text/csv";
}
0

There are 0 best solutions below