473,320 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to force Response.WriteFile waiting until a file is downloaded?

Hi,

Response.WriteFile (or Response.OutputStream.Write) finishes
immediately, not after the file is completely downloaded.
It finishes before (!) the user clicks the "Save" or "Open" browser
button, file size doesn't matter. I'm not possible to track if the file
was completely downloaded or if the user only clicked the link and
cancelled the download.

I've created a simple "solution" of this problem, which waits until the
user clicks "Cancel" or "Open".

Two things to solve:

When the user clicks "Save", IsClientConnected remains true until
the user closes browser window... (Navigation to another page doesn't
close the connection.)

Moreover, I don't know how to read an information about whether the file
was fully downloaded or not. Something like
Response.TotalBytesThatReallyArrivedToTheUser..:)

thanks
ProJee
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim path As String = "c:\file.mp3"
Response.ClearHeaders()
Response.ClearContent()
Response.Clear()
Response.Buffer = False
Response.BufferOutput = False
Response.AddHeader("Content-Disposition",
"attachment;filename=file.mp3")
Response.AppendHeader("Content-Length", FileLen(path))
Response.ContentType = "image/jpg"

Dim bytesToGo As Integer
Dim bytesRead As Integer
Dim fStream
Dim byteBuffer

Response.WriteFile("c:\file.mp3", False)

Do
Threading.Thread.Sleep(100)
Loop While Response.IsClientConnected

'it comes here AFTER the connection is broken ("Open", "Cancel" 'or
browser exit after "Save") which is great, but I don't know 'if the
file was downloaded; to detect user action.

Response.End()

End Sub

Nov 18 '05 #1
0 1938

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Todd Richardson | last post by:
I have written a web form which downloads files to the client automatically. After the download completes, I would like to delete the file that was downloaded. I can't tell how to wait until the...
2
by: Miguel Dias Moura | last post by:
Hello, in my web site i display some links to PDF files. This links are loaded from a database. Anyway, when i click these links the PDF files are open in the visitors browser and in Acrobat. ...
7
by: tma | last post by:
How can I force a file to be downloaded to the client when the click a link button, rather than show the file in the browser window (or another window). I want the user to be prompted to open or...
8
by: Scott C. Reynolds | last post by:
I want to serve a PDF right to a web page (cannot link browser directly to PDF file). Stumbled across Response.WriteFile this morning. On my machine (XP Pro) this worked fine: private void...
3
by: jeffpriz | last post by:
I'm have a situation where I need to put a download link/button on a page, where the file to be downloaded does not exist on our webservers .... So I'm using Response.WriteFile (i've also tried...
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
1
by: greg | last post by:
Hi I have a link on a page that points to a file inside the site that I want to be downloaded loke in page_load I write linkFile.NavigateUrl = Request.ApplicationPath + "/somepath/file.iif";...
5
by: gaubo79 | last post by:
I am wishing to force the Open|Save dialog box for a PDF and Excel file. I am using the following code: Response.Clear(); Response.ContentType = "application/octet-stream";...
3
by: MJP | last post by:
I have a button which kicks off the generation of a report after which the file will be downloaded. The report generation can take a long time, so client side onclick event of the button also...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.