In my asp.net application want to refresh the current page after user has download the excel file but every time the code throws an exception says:
"Cannot redirect after HTTP headers have been sent".
I've already almost every solution on web but none of them worked for me. I've tried this approach this approach also but that also did work for me.
this is my code:
wb.Worksheets.Add(dt, "Docket_Cycle_Performance");
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.ContentType =
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("content-disposition",
"attachment;filename=DocketCyclePerformance-"
+ System.DateTime.Now + ".xlsx");
using (MemoryStream MyMemoryStream = new MemoryStream())
{
wb.SaveAs(MyMemoryStream);
MyMemoryStream.WriteTo(Response.OutputStream);
Response.Flush();
if (!Response.IsRequestBeingRedirected)
{
Response.Redirect(Request.RawUrl);
}
Response.End();
}
Is there any solution of this problem.. Thanks!!