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

P

ProJee

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
 

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,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top