Exporting a Crystal Report to a PDF file using ASP.NET. It works ok, but the page doesn't seem to load the first time. I end up having to hit refresh for it to come up. Oddly, with a break point in my Page_Load event, when I hit refresh it runs the function twice. Anybody have any ideas? Here's the code.
Thanks.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
' Define Crystal Reports variables
Dim crReportDocument As ReportDocument
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
' 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 ORDER BY DueDate"
' 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
oStream = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat)
Response.Clear()
Response.ContentType = "application/pdf"
Response.Buffer = True
Response.BinaryWrite(oStream.ToArray())
Response.Flush()
Response.Close()
End Sub




Reply With Quote