I work with asp.net and C #, I am trying to generate 190 reports and only one is being generated and when trying to generate the following, I get the following error: "The server can not attach a header after sending the headers HTTP. "
investigate and these two links " link " and " link " to solve the problem and I do not understand how it should be implemented in my code.
for (int i = 0; i <= ListaEmpleado.Length; i++)
{
Stream oStream = null;
byte[] byteArray = null;
if (!ListaEmpleado[i].Equals("*"))
{
TablaGeneral = _operacion.ObtenerDatosDesprendiblePagoDestajo(IdEmpresa, Periodo, CentroCosto, Ciudad, "*", ListaEmpleado[i].ToString());
}
TablaDetalleDEV = _operacion.ObtenerDetallesPagoDestajo(IdEmpresa, ListaEmpleado[i].ToString(), Periodo, "DEV");
TablaDetalleDED = _operacion.ObtenerDetallesPagoDestajo(IdEmpresa, ListaEmpleado[i].ToString(), Periodo, "DED");
reporte = new ReportDocument();
reporte.Load(Server.MapPath("~/Reportes/Operaciones/" + nombreReporte + ".rpt"));
reporte.SetDataSource(TablaGeneral);
reporte.Subreports[0].SetDataSource(TablaDetalleDEV);
reporte.Subreports[1].SetDataSource(TablaDetalleDED);
oStream = reporte.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
byteArray = new byte[oStream.Length];
oStream.Read(byteArray, 0, Convert.ToInt32(oStream.Length - 1));
string empleado = "";
if (!ListaEmpleado[i].Equals("*"))
{
empleado = ListaEmpleado[i];
}
using (var mStream = (MemoryStream)reporte.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat))
{
Response.AddHeader("Content-Disposition", "attachment;FileName=" + RazSocial + " " + empleado + ".pdf");
Response.Buffer = true;
Response.ContentType = "application/pdf";
Response.BinaryWrite(byteArray);
Response.Flush();
Response.Clear();
}
HttpContext.Current.ApplicationInstance.CompleteRequest();
//Response.End();
reporte.Dispose();
reporte.Close();
reporte = null;
GC.Collect();
}
Thank you very much for the help. if they have a link where it is explained better they will also be of great help