Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > How can I know when a file has been downloaded?

Reply
Thread Tools

How can I know when a file has been downloaded?

 
 
lichaoir
Guest
Posts: n/a
 
      07-18-2008
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!
 
Reply With Quote
 
 
 
 
jashin724@gmail.com
Guest
Posts: n/a
 
      07-18-2008
On Jul 18, 10:09*am, lichaoir <(E-Mail Removed)> 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 ...
 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      07-18-2008
On Jul 18, 4:09*am, lichaoir <(E-Mail Removed)> 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/libr...connected.aspx
 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      07-18-2008
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How a script can know if it has been called with the -i command line option? Michele Simionato Python 11 12-23-2006 03:35 PM
know can I know how much object has been created??? sayoyo@yahoo.com Ruby 2 03-31-2006 08:09 PM
The printing has been stopped and this job has been add to the queu? dejola Computer Support 6 12-30-2005 03:26 AM
How can we know if a HttpServletResponse has been redirected ? Bruno Thomas Java 2 09-13-2005 02:47 PM



Advertisments