簡體   English   中英

在Response.End()之后執行代碼

[英]Executing code after Response.End()

單擊按鈕后,我正在生成一個Excel文件下載。 下載Excel之后,響應將停止並結束。 您能否建議我如何防止停止,以便用戶無需刷新頁面就可以下載所需的次數?

Response.Clear();
Response.ContentType = 
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader
(
  "content-disposition", 
  "attachment;  filename=PFMWarehouseList_" 
  + DateTime.Today.ToString("dd/MM/yyyy") + ".xlsx"
);

Response.BinaryWrite(pck.GetAsByteArray());

//HttpContext.Current.ApplicationInstance.CompleteRequest();
Response.End();
string Url = "FullPatchYourFile";
FileInfo file = new FileInfo(Url);

try
{
    Response.Clear();
    Response.ClearHeaders();
    Response.ClearContent();
    Response.AddHeader("content-disposition", "attachment;filename=YourFileName");
    Response.AddHeader("Content-Type", "application/zip"); 
    Response.ContentType = ".zip"; //YourExtensionFile
    Response.AddHeader("Content-Length", file.Length.ToString());
    Response.WriteFile(file.FullName);
    Response.TransmitFile(file.FullName);
    Response.End();
}
finally
{
    Your instructions after response.end();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM