Working with BinaryWrite

J

Jeff Dillon

From a client, I call

http://server/retrieve.aspx?guid=somevalue

Then, in page_load of retrieve.aspx I have

filespec = "test.mdb"
pathspec = "c:\"

MyFileStream = New FileStream(pathspec & filespec, FileMode.Open)
FileSize = MyFileStream.Length

Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()

Response.BufferOutput = True
Response.ContentType = "application/asp-unknown"
Response.AddHeader("content-disposition", "attachment; filename=" &
filespec)
Response.BinaryWrite(Buffer)
Response.Flush()


But if I have the above http link in an email message for example, the file
downloads just fine with the Save As dialog, but back in the browser, it
displays:

Action canceled
Internet Explorer was unable to link to the Web page you requested.
The page might be temporarily unavailable.


How can I place a meaningful message in the browser, or redirect?
Response.Redirect or Server.Transfer are ignored after the Flush. Any
ideas?

Jeff
 
M

Matt Berther

Hello Jeff,

After Response.Flush, try Response.End(). My guess is you're getting further
into the Page processing than you want to.

When I do things like this, I typically implement them as an HttpHandler,
however, that's beyond the scope of your question. :=)
 

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,756
Messages
2,569,540
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top