G
Gregory Silvano
I have reproduced this problem on several machines (all different
configs) and don't see anything wrong with the code. The code below
(or very similar) is from Microsoft (help files, newsgroup posts,
etc.) and available at several other resources on the Web.
If you click on the LinkButton once or twice it works without
problems. However, on the third (sometimes the second) click the
browser hangs. It never even gets to a breakpoint in the PageLoad
event. Sometimes it'll just spit out the gif binary code in the page,
floating above the existing browser page like a watermark. Weird.
Can somebody reproduce this behavior?
Just create a WebApplication and throw a LinkButton on the page,
keeping the default name. Put the code below in the codebehind and
throw a gif or something in the same directory as your web form,
calling it test.gif.
Private Sub LinkButton1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim MyFileStream As System.IO.FileStream = New _
System.IO.FileStream(Server.MapPath("test.gif"), _
System.IO.FileMode.Open)
'Get the file length
Dim FileSize As Integer = MyFileStream.Length
'Read the file into the buffer and close the file stream
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()
'I've also tried Response.Clear and .ClearContents
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
'We want to force a download
Response.AddHeader("Content-Disposition", _
"attachment; filename=test123.gif")
Response.AddHeader("Content-Length", FileSize)
Response.BinaryWrite(Buffer)
End Sub
I appreciate any insight you may have. I have been having problems
getting WriteFile to work in SSL, so that's why I'm using the
BinaryWrite approach. Thanks...
Regards,
Gregory Silvano
configs) and don't see anything wrong with the code. The code below
(or very similar) is from Microsoft (help files, newsgroup posts,
etc.) and available at several other resources on the Web.
If you click on the LinkButton once or twice it works without
problems. However, on the third (sometimes the second) click the
browser hangs. It never even gets to a breakpoint in the PageLoad
event. Sometimes it'll just spit out the gif binary code in the page,
floating above the existing browser page like a watermark. Weird.
Can somebody reproduce this behavior?
Just create a WebApplication and throw a LinkButton on the page,
keeping the default name. Put the code below in the codebehind and
throw a gif or something in the same directory as your web form,
calling it test.gif.
Private Sub LinkButton1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim MyFileStream As System.IO.FileStream = New _
System.IO.FileStream(Server.MapPath("test.gif"), _
System.IO.FileMode.Open)
'Get the file length
Dim FileSize As Integer = MyFileStream.Length
'Read the file into the buffer and close the file stream
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()
'I've also tried Response.Clear and .ClearContents
Response.ClearHeaders()
Response.ContentType = "application/octet-stream"
'We want to force a download
Response.AddHeader("Content-Disposition", _
"attachment; filename=test123.gif")
Response.AddHeader("Content-Length", FileSize)
Response.BinaryWrite(Buffer)
End Sub
I appreciate any insight you may have. I have been having problems
getting WriteFile to work in SSL, so that's why I'm using the
BinaryWrite approach. Thanks...
Regards,
Gregory Silvano