Detect File is Completely Download by Client

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>
 
M

Marina

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.
 
M

Matt Dockerty

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.
 
M

Marina

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.
 
B

Bruce Barker

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)
 
M

Matt Dockerty

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>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top