How can I know when a file has been downloaded?

Discussion in 'ASP .Net' started by lichaoir, Jul 18, 2008.

  1. lichaoir

    lichaoir Guest

    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!
     
    lichaoir, Jul 18, 2008
    #1
    1. Advertising

  2. lichaoir

    Guest

    On Jul 18, 10:09 am, lichaoir <> wrote:
    > 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 ...
     
    , Jul 18, 2008
    #2
    1. Advertising

  3. On Jul 18, 4:09 am, lichaoir <> wrote:
    > 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!


    Response.OutputStream.Write has been completed because the server sent
    the whole file to a client. The client is still receiving the data and
    I think you can try to check this using Response.IsClientConnected

    http://msdn.microsoft.com/en-us/library/system.web.httpresponse.isclientconnected.aspx
     
    Alexey Smirnov, Jul 18, 2008
    #3
  4. lichaoir

    bruce barker Guest

    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)

    lichaoir wrote:
    > 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!
     
    bruce barker, Jul 18, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Um95?=
    Replies:
    1
    Views:
    2,044
    =?Utf-8?B?Um95?=
    May 2, 2005
  2. Rob Nicholson
    Replies:
    12
    Views:
    815
    Edwin Knoppert
    Dec 6, 2005
  3. Bruno Thomas
    Replies:
    2
    Views:
    1,358
    Bruno Thomas
    Sep 13, 2005
  4. Michele Simionato
    Replies:
    11
    Views:
    464
    vasudevram
    Dec 23, 2006
  5. Replies:
    2
    Views:
    126
Loading...

Share This Page