Working with BinaryWrite

  • Thread starter Thread starter Jeff Dillon
  • Start date Start date
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
 
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. :=)
 
Back
Top