How can I detect when a file download has completed in ASP.NET?

前端 未结 6 1161
太阳男子
太阳男子 2021-01-31 21:23

I have a popup window that displays \"Please wait while your file is being downloaded\". This popup also executes the code below to start the file download. How can I close th

6条回答
  •  深忆病人
    2021-01-31 22:12

    An idea:

    If you handle the file downloading yourself in server side code by writing chunk by chunk to the response stream, then you'll know when the file had finished downloading. You would simply have to connect the FileStream to the response stream, send data chunk by chunk, and redirecting after complete. This can be inside your popup window.

    Response.ContentType = "application/octet-stream";
    Response.AppendHeader("content-disposition", "attachment; filename=bob.mp3");
    Response.AppendHeader("content-length", "123456789");
    

    Make sure you check Response.IsClientConnected when writing out to the response stream.

提交回复
热议问题