Response.BinaryWrite fires twice

G

Guest

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.
 
B

Bruce Barker

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,836
Messages
2,569,748
Members
45,545
Latest member
rapter____0

Latest Threads

Top