Response.BinaryWrite fires twice

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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)
 
Back
Top