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

前端 未结 6 1157
太阳男子
太阳男子 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 21:53

    The way to do that is in your pop-up to call the server via AJAX polling for some response which would indicate the file was flushed.

    Ex: right before sending the file, store sessionID+FileName in a DB or session or what have you.

    On the client, in your popup, poll a web-service via AJAX - this could even be a WebMethod like Bool IsContentFlushed(string sessionID, string fileName);

    After you do Response.Flush(); remove this sessionID+FileName from your store.

    Call Response.Close() instead of Response.End() - the later is very brutal, and is usually over-kill.

提交回复
热议问题