Problem with adding parameter

M

Morten Snedker

I am trying to move from having a crystalreportviewer to just
launching the PDF, but have difficulties adding a parameter value for
the underlying stored procedure

The commented-out part works in another context and I'm trying to make
it fit in, but can't see through it.

Thanks a bunch for any help!

Regards /Snedker

'--code begin
crReportDocument = New ReportDocument()

crReportDocument.Load(Server.MapPath("Reports\Erklaering.rpt"))
Fname = "c:\exports\" & Session("vvsID") & ".pdf"

'Dim field1 As ParameterField =
Me.CrystalReportViewer1.ParameterFieldInfo(0)
'Dim val1 As ParameterDiscreteValue = New
ParameterDiscreteValue
'val1.Value = Session("vvsID")
'field1.CurrentValues.Add(val1)


crDiskFileDestinationOptions = New
DiskFileDestinationOptions()
crDiskFileDestinationOptions.DiskFileName = Fname
crExportOptions = crReportDocument.ExportOptions

With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType = ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With

crReportDocument.Export()

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(Fname)
Response.Flush()
Response.Close()
System.IO.File.Delete(Fname)
'--code end
 
M

Morten Snedker

Got it to work. Finally!

Maybe someone else can enjoy the code it took me hours and hours to
generate.

Printing to PDF without using CrystalReportViewer and with parameter
on the underlying stored procedure:

Sub PDFExport()

Dim crReportDocument As ReportDocument
Dim crExportOptions As ExportOptions
Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
Dim Fname As String

Try

Dim dv As New ParameterDiscreteValue
dv.Value = Session("vvsID")

crReportDocument = New ReportDocument()

crReportDocument.Load(Server.MapPath("Reports\Erklaering.rpt"))
crReportDocument.SetParameterValue(0, dv.Value)
crReportDocument.SetDatabaseLogon("somename", "pass",
"yourserver", "databasename")
Fname = "c:\exports\" & Session("vvsID").ToString & ".pdf"

crDiskFileDestinationOptions = New
DiskFileDestinationOptions()
crDiskFileDestinationOptions.DiskFileName = Fname
crExportOptions = crReportDocument.ExportOptions

With crExportOptions
.DestinationOptions = crDiskFileDestinationOptions
.ExportDestinationType =
ExportDestinationType.DiskFile
.ExportFormatType = ExportFormatType.PortableDocFormat
End With

crReportDocument.Export()

Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.WriteFile(Fname)
Response.Flush()
Response.Close()
System.IO.File.Delete(Fname)


Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub


Now it just needs to be moved to a reusable class.

cheers!
 

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,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top