Detect File is Completely Download by Client

  • Thread starter Thread starter RC
  • Start date Start date
R

RC

how to detect file is completely downloaded from client by following code?

<%@ Page language="C#" debug="true" %>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e) {
Response.ContentType="application/zip";
Response.AppendHeader("Content-Disposition","attachment;
filename=myzipfile.zip");
Response.WriteFile(@"c:\inetpub\wwwroot\myzipfile.zip");
Response.Flush();
}
</script>
 
You can't. Once the file is sent, you have no way of knowing how long it
travels over the web, or how slow the other person's connection is, or how
long it takes. Once you send it, your job is done.
 
Marina said:
You can't. Once the file is sent, you have no way of knowing how long it
travels over the web, or how slow the other person's connection is, or how
long it takes. Once you send it, your job is done.

Um, wrong, you don't just chuck a file onto the Internet and hope it reaches
it's destination. A stateful connection takes place.

There is a solution. You could send it about 512 bytes a time with
Response.BinaryWrite / Response.Flush and check for
Response.IsClientConnected between each block. If that is ever false, the
connection has dropped and the user doesn't have their file.
 
His code wasn't doing that. Presumably he wanted to know if there was a way
to check that after executing that piece of code. He's got to rewrite that
block of code first.
 
this has the minor hole, that the last write may not be received by the
client even though the server successfully sent it..

-- bruce (sqlwork.com)
 
Bruce Barker said:
this has the minor hole, that the last write may not be received by the
client even though the server successfully sent it..

HTTP 1.1 has persistent connections where the connection remains open for a
little while after the file is recieved in case the client wants something
else from the server. Unless the client needs to talk in HTTP 1.0 (extremely
rare) or you're explicitly sending a 'Connection: close' header the last
block will be detected too.
-- bruce (sqlwork.com)
<snip>
 
Back
Top