473,378 Members | 1,438 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,378 software developers and data experts.

Response.BinaryWrite fires twice

Hi,

I am trying to display a pdf file on the web. It is working fine but the
Page_Load method is running twice before displaying the page. Here is the
code that I am using

Private Sub ReadPdfFile(ByVal strFilepath As String)
'Create WebClient Object
Dim objWebClient As New WebClient
'Create Byte Array to download data
Dim byteBuffer() As Byte = objWebClient.DownloadData(strFilepath)

'Read Data
If Not byteBuffer Is Nothing Then
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.AddHeader("content-length", byteBuffer.Length.ToString())
'Response.ClearHeaders()
Response.BinaryWrite(byteBuffer)
Response.End()
End If
End Sub

I am thinking it is due to Response object. How could I solve this?

Thanks,
Sridhar.
Dec 12 '05 #1
1 2512
some options.

1) you have linked in the page load event twice.
2) you have autheication turned on and the browser is requesting the page
twice.
3) you are using an older IE, that does mutilple request without caching.

also you should change the code to:

Response.Buffer = True
Response.ClearHeaders()
Response.ClearContent()
Response.ContentType = "application/pdf"
Response.AddHeader("content-length",
byteBuffer.Length.ToString())
Response.AddHeader( "Content-Disposition", "inline;
filename=report.pdf" );
Response.BinaryWrite(byteBuffer)
Response.End()

you also should set the cache times

-- bruce (sqlwork.com)
"Sridhar" <Sr*****@discussions.microsoft.com> wrote in message
news:CA**********************************@microsof t.com...
Hi,

I am trying to display a pdf file on the web. It is working fine but
the
Page_Load method is running twice before displaying the page. Here is the
code that I am using

Private Sub ReadPdfFile(ByVal strFilepath As String)
'Create WebClient Object
Dim objWebClient As New WebClient
'Create Byte Array to download data
Dim byteBuffer() As Byte = objWebClient.DownloadData(strFilepath)

'Read Data
If Not byteBuffer Is Nothing Then
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.AddHeader("content-length",
byteBuffer.Length.ToString())
'Response.ClearHeaders()
Response.BinaryWrite(byteBuffer)
Response.End()
End If
End Sub

I am thinking it is due to Response object. How could I solve this?

Thanks,
Sridhar.

Dec 13 '05 #2

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

Similar topics

5
by: katrinaVictim | last post by:
Question: I get the eror listed at the bottom of the post. What can I do to make the response of the x1.send a "binary" type? Or, in general, how can I just "make this work"? <%@...
3
by: spmm# | last post by:
Hi! My ASP.NET page gets a pdf-file from a SQLServer database and writes it in a browserwindow, using Response.BinaryWrite. It basically looks like this: public class WebForm1 :...
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 ...
0
by: Thomas Gurath | last post by:
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...
2
by: ATS | last post by:
HOWTO Override ASP's Response output for 2003/IIS. Please help, I want to have an ASP page write back EVERYTHING to the ASP Response. That includes HTTP Headers. I want my ASP to look...
5
by: Katie | last post by:
Hi, I made a posting a while ago regarding doing a binarywrite of a large file in chunks and got a lot of helpful responses. I was able to make it work then. Unfortunately when the project is...
5
by: twiggy182 | last post by:
Hi, I really need you help because I'm not very familliar with ASP and I could not find any solution to my problem. To put you in situation, I have a CGI to which I send a file name, and that...
1
by: mattridings | last post by:
Hi gang, Have a script that works fine. However, it's really cpu intensive and I'm looking for suggestions on a) whether or not that's normal and if so b)a better way of doing it. Script is...
14
by: S N | last post by:
I am using the following code to hide the download url of files on my website. The code uses Response.Binarywrite to send file to the client. Kindly indicate the maximum size of the file that can be...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?

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.