By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,631 Members | 892 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,631 IT Pros & Developers. It's quick & easy.

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

P: n/a

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

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.Buffer = False
Response.BufferOutput = False
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)

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.


End Sub

Nov 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.