473,396 Members | 1,683 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Response.BinaryWriter causing IE File Download dialog to appear twice

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
Nov 20 '05 #1
0 2046

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pedro Fonseca | last post by:
Greetings! In my PHP website I'm trying to raise a File Download dialog directly in a WindowsCE IE client with the following code: header( "Content-Type: application/octet-stream\n" );...
5
by: W.Guerlich | last post by:
I've got a Java servlet that delivers large database resultsets transformed to Excel with the HSSF library. In some cases it takes more than 15 minutes before transformation is done and content can...
5
by: PJ | last post by:
When streaming a file attachment to the response stream, should I set Response.BufferOutput = False or Response.Buffer = False or both?
1
by: Dan | last post by:
Hi I've created a generic 'Report' class that takes a DataView from a DataGrid control and writes it out to the response as a csv file for download. Basically, when a user clicks the download...
2
by: John Spiegel | last post by:
Hi all, How does one allow a user to download a file WITH selecting where it should be downloaded to on their machine? Also, when using the WebClient.Download method, will the destination path...
11
by: Russ | last post by:
My web app writes some binary data to a file at the client site via Response.Write and Response.BinaryWrite. This action is accomplished in response to a button click, with C# code behind as...
4
by: Dorte | last post by:
Hi, I am using the code below to stream a CSV file with the response object. Dim FileName As String = "Test.csv" With Web.HttpContext.Current.Response ...
3
by: Buddy Ackerman | last post by:
I'm trying to write files directly to the client so that it forces the client to open the Save As dialog box rather than display the file. On some occasions the files are very large (100MB+). On...
1
by: showson1 | last post by:
Hi all! I have some files that are basically a TIF with an ASCII header. I wrote an app that reads in the file, pulls some values from the header and writes out everything after the header as a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.