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

Response.BinaryWriter causing IE File Download dialog to appear twice

P: n/a
I have some code that reads a file from disk and inserts it into the
http response. When the user clicks the file's title linkbutton, the
File Download prompt appears twice if they select Open rather than
Save. This occurs with zip and octet-stream content types, I'm not
sure about pdf and doc. Stepping through the code, control never comes
back to the IDE between the two File Download dialogs, so it doesn't
appear that more than one event is firing. Can anyone tell me how to
prevent this? Here is the code:

Sub BookTitle_Click(ByVal sender As Object, ByVal e As

Dim da As New DataAccess
Dim lb As LinkButton = CType(e.CommandSource, LinkButton)
Dim FilePath As String =

Dim MyFileInfo As New
FileInfo(ConfigurationSettings.AppSettings("Librar yPath").ToString &
Dim MyFileStream As New FileStream(MyFileInfo.FullName,
Dim FileSize As Long = MyFileStream.Length
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))

With Response

Select Case MyFileInfo.Extension.ToUpper
Case ".ZIP"
.ContentType = "application/zip"
Case ".PDF"
.ContentType = "application/pdf"
Case ".DOC"
.ContentType = "application/doc"
Case Else
.ContentType = "application/octet-stream"
End Select

.AddHeader("content-disposition", "attachment; filename="
& MyFileInfo.Name)
End With
Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.