I have following code to generate an excel sheet from the provided datatable and I modified it to generate two excel sheets.
if (dt.Rows.Count > 0)
GenerateExcelSheet(dt);
if (dtSplit.Rows.Count > 0)
GenerateExcelSheet(dtSplit);
private void GenerateExcelSheet(DataTable dt)
{
string fileName = string.Format("Foodlist-{0}.xls", DateTime.Now.ToString("ddMMMyyyy-hh:mm:tt"));
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));
Response.ContentType = "application/ms-excel";
//Code
Response.Write("<table>");
//My code goes here
Response.Write("</table>");
Response.End();
}
From above code GenerateExcelSheet(dt); is executing and download the file but
if (dtSplit.Rows.Count > 0) and rest of the code is not executing. After research I found that Response.End(); cause to end of the execution the current page. Is there any way to overcome this?