Hi,
I'm having problem in exporting report with parameters to pdf. I had no problems at all on crystalreportviewer. Though pdf file is successfully created but no data is shown, it seems that it took the .rpt file from my source folder to convert into pdf.
How can I bind the pdf to my datasource?
Kindly help.
Below are my codes:
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Public Class WebForm2
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.cachedtest31 = New treeview1.Cachedtest3
'
'cachedtest31
'
Me.cachedtest31.CacheTimeOut = System.TimeSpan.Parse("02:10:00")
Me.cachedtest31.IsCacheable = True
Me.cachedtest31.ShareDBLogonInfo = False
End Sub
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Protected WithEvents cachedtest31 As treeview1.Cachedtest3
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Declare variables needed to pass the parameters
' to the viewer control.
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim paramField1 As New CrystalDecisions.Shared.ParameterField
Dim paramField2 As New CrystalDecisions.Shared.ParameterField
Dim paramFields As New CrystalDecisions.Shared.ParameterFields
Dim discreteVal1 As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim discreteVal2 As New CrystalDecisions.Shared.ParameterDiscreteValue
Dim rangeVal As New CrystalDecisions.Shared.ParameterRangeValue
Dim crtableLogoninfos As New CrystalDecisions.Shared.TableLogOnInfos
Dim crtableLogoninfo As New CrystalDecisions.Shared.TableLogOnInfo
Dim crConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo
Dim CrTables As CrystalDecisions.CrystalReports.engine.Tables
Dim CrTable As CrystalDecisions.CrystalReports.engine.Table
Dim TableCounter
Dim crReportDocument As New test3
crReportDocument.Load()
With crConnectionInfo
.ServerName = "TCM-IT01\SQL"
.DatabaseName = "SBODemo_US"
.UserID = "sa"
.Password = "Pass123"
End With
CrTables = crReportDocument.Database.Tables()
For Each CrTable In CrTables
crtableLogoninfo = CrTable.LogOnInfo
crtableLogoninfo.ConnectionInfo = crConnectionInfo
CrTable.ApplyLogOnInfo(crtableLogoninfo)
Next
' Set the name of the parameter field, this must match a
' parameter in the report.
paramField1.ParameterFieldName = "ItemCode"
discreteVal1.Value = TextBox1.Text
paramField1.CurrentValues.Add(discreteVal1)
paramField2.ParameterFieldName = "ItemCodeT"
discreteVal2.Value = TextBox2.Text
paramField2.CurrentValues.Add(discreteVal2)
' Add the parameter to the parameter fields collection.
paramFields.Add(paramField1)
paramFields.Add(paramField2)
' Set the parameter fields collection into the viewer control.
CrystalReportViewer1.ParameterFieldInfo = paramFields
CrystalReportViewer1.DisplayGroupTree = False
CrystalReportViewer1.SeparatePages = False
CrystalReportViewer1.ReportSource = crReportDocument
Dim myExportOptions As ExportOptions
myExportOptions = crReportDocument.ExportOptions
Dim crDiskFileDestinationOptions = New DiskFileDestinationOptions
crDiskFileDestinationOptions.DiskFileName = "c:\temp\item.pdf"
myExportOptions = crReportDocument.ExportOptions
With myExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With
Try
crReportDocument.Export()
Catch err As Exception
'messagebox.Show(err.ToString())
End Try
Dim oStream As New IO.MemoryStream()
oStream = crReportDocument.ExportToStream(ExportFormatType.PortableDocFormat)
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/pdf"
Response.WriteFile("c:\temp\items.pdf")
Response.Flush()
Response.Close()
End Sub
End Class