How can I know when a file has been downloaded?

  • Thread starter Thread starter lichaoir
  • Start date Start date
L

lichaoir

Hmm... What I really mean is...

I want to write a program to monitor file downloading. I want to be
notified when a file has been downloaded, so I can write a record into
database. How should I implement this?

My colleague has written a program, but is has some problem:

-------------------------------------------------------------------------------------------------------------------------------------------
Response.BufferOutput = false;
FileStream fs = File.OpenRead(Server.MapPath("~/test1.zip"));
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
Response.OutputStream.Write(data, 0, data.Length);

fs.Close();
fs.Dispose();

// Add a record to database......
 
Hmm... What I really mean is...

I want to write a program to monitor file downloading. I want to be
notified when a file has been downloaded, so I can write a record into
database. How should I implement this?

My colleague has written a program, but is has some problem:

---------------------------------------------------------------------------­----------------------------------------------------------------
        Response.BufferOutput = false;
        FileStream fs = File.OpenRead(Server.MapPath("~/test1.zip"));
        byte[] data = new byte[fs.Length];
        fs.Read(data, 0, data.Length);
        Response.OutputStream.Write(data, 0, data.Length);

        fs.Close();
        fs.Dispose();

        // Add a record to database......
---------------------------------------------------------------------------­----------------------------------------------------------------

The problem is, when the file is downloaded nearly 80%, a record has
already been there in database. What's the problem? Please help!
Thanks!

I don't know, I have a same problem too, I think there is something
between Response and Client, maybe IIS or Browser have some cache
or ...
 
there is really no way server side to know if the browser recieved the
complete file. generally there are proxy servers and firewalls between
the server and client, any of which might lose connection after the
server is done sending the file. the only way is a client app that does
the download.

-- bruce (sqlwork.com)
 
Back
Top