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
DataGridCommandEventArgs)
Dim da As New DataAccess
Dim lb As LinkButton = CType(e.CommandSource, LinkButton)
Dim FilePath As String =
da.GetBookFileNameByTitle(lb.Text.ToString)
Dim MyFileInfo As New
FileInfo(ConfigurationSettings.AppSettings("Librar yPath").ToString &
FilePath)
Dim MyFileStream As New FileStream(MyFileInfo.FullName,
FileMode.Open)
Dim FileSize As Long = MyFileStream.Length
Dim Buffer(CInt(FileSize)) As Byte
MyFileStream.Read(Buffer, 0, CInt(FileSize))
MyFileStream.Close()
With Response
.Clear()
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)
.BinaryWrite(Buffer)
.Flush()
End With