2014-02-28 61 views
0

我正在按鈕單擊生成excel文件下載。下載excel後,響應正在停止並結束。您能否建議我如何防止停止,以便用戶無需刷新頁面即可根據需要多次下載?Response.End()後執行代碼

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(); 
+0

可能會開始下載一個新的頁面.. – iJade

+0

你可以告訴你如何實現一個按鈕的點擊,或者是你試過嗎? –

+1

如果你想避免回發,我會建議JavaScript。 – snowYetis

回答

0
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(); 
} 
+0

雖然這可能會產生問題,但也請提供一個簡短的說明,說明您的代碼的作用以及爲什麼它解決了最初的問題。不要在沒有任何評論的情況下刪除一些代碼行。 – user1438038