I'm exporting a Crystal Report to a PDF File in ASP.NET, but I'm having a problem where the PDF won't load the first time around...the page opens up blank, but if I refresh it, Adobe kicks off and the page is displayed.
Here is the source code:
'Put user code to initialize the page here
' Define Crystal Reports variables
Dim crReportDocument As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
Dim Fname As String ' Temp PDF File Name
Dim SQLConn As SqlClient.SqlConnection ' SQL Connection
Dim SQLDA As SqlClient.SqlDataAdapter ' SQL Data Adapter
Dim dsDataSet As New DataSet ' Dataset
Dim strSQL As String ' SQL Statement
Dim oStream As System.IO.MemoryStream ' Memory Stream
' Instantiate the SQL Connection
SQLConn = New SqlClient.SqlConnection("Persist Security Info=False;server=MyServer;database=MyDB;User ID=sa;Password=password")
' SQL SELECT Statement
strSQL = "SELECT * FROM Tasks"
' Instantiate the SQL DataAdapter
SQLDA = New SqlClient.SqlDataAdapter(strSQL, SQLConn)
' Populate the DataSet
SQLDA.Fill(dsDataSet, "Tasks")
' Instantiate the Crystal Report Document (crTasks.rpt)
crReportDocument = New crTasks
Try
' Set the DataSource for the Report as the DataSet
crReportDocument.SetDataSource(dsDataSet)
Catch ex As Exception
End Try
' Export the report to a Memory Stream
oStream = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat)
' The following code writes the pdf file to the Client’s browser.
Response.Clear()
Response.ContentType = "application/pdf"
Response.Buffer = True
Response.BinaryWrite(oStream.ToArray())
Response.Flush()
Response.Close()
Any ideas what might cause this?


Reply With Quote