2014-02-28 42 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