Batch of CRYSTAL REPORTS into PDF with Parameters

I have a batch process that gets Crystal reports out of a certain folder that turns them into PDF's without parameters and now I have CR that need to have parameters fed into them.  

They could be all different types of parameters, including ones with multiple parameters.  I need to be able to feed the parameters into different reports doing a batch process that runs.

I am guessing I would use a table to feed these into CR?  I am using VB.NET  This is an extention of another question which here is the code.  Thanks ahead of time vikingg97

Imports System.Data
Imports System.Data.SqlClient
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports System.IO
Imports Microsoft.VisualBasic

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.Button1.Location = New System.Drawing.Point(256, 32)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(144, 23)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Generate PDF from CR"
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(616, 461)
        Me.Name = "Form1"
        Me.Text = "Form1"

    End Sub

#End Region

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'Place the following name spaces at the top of the code page
        Dim fileList() As String = System.IO.Directory.GetFiles("c:\inetpub\wwwroot\MCNETWebSite\IT_Work\")

        For Each fileSource As String In fileList


            If Strings.Right(fileSource, 4) = ".rpt" Then
                'Crystal Export Code Here
                Dim CrReport As New ReportDocument
                CrReport.Load(fileSource, OpenReportMethod.OpenReportByDefault)
                Dim CrExportOptions As ExportOptions
                Dim CrDiskFileDestinationOptions As New DiskFileDestinationOptions
                Dim CrFormatTypeOptions As New PdfRtfWordFormatOptions

                ' Set the destination path and file name
                ' 41 is the spot where I need to get file name 41 (34 old)
                Dim mid As String
                mid = Strings.Mid(fileSource, 41)

                ' Gets the length of the filename
                Dim LengthObjName As String
                LengthObjName = Strings.Len(mid)

                ' Gets charactor to start at for taking out of the .rpt
                Dim LengthFrom_rpt As String
                LengthObjName = CInt(LengthObjName - 4)

                ' Gets the actual file name minus the .rpt extension
                Dim strVarName As String
                strVarName = Strings.Left(mid, LengthObjName)

                'Getobj = Microsoft.VisualBasic.GetObject(fileSource)
                Dim pdf_path As String
                pdf_path = "c:\CR_Convert_to_PDF\" & strVarName & ".pdf"
                CrDiskFileDestinationOptions.DiskFileName = pdf_path

                'Specify a page range (optional)
                CrFormatTypeOptions.FirstPageNumber = 1
                CrFormatTypeOptions.LastPageNumber = 3
                CrFormatTypeOptions.UsePageRange = True

                'Set export options
                CrExportOptions = CrReport.ExportOptions

                With CrExportOptions
                    'Set the destination to a disk file
                    .ExportDestinationType = ExportDestinationType.DiskFile
                    'Set the format to PDF
                    .ExportFormatType = ExportFormatType.PortableDocFormat
                    'Set the destination options to DiskFileDestinationOptions object
                    .DestinationOptions = CrDiskFileDestinationOptions
                    .FormatOptions = CrFormatTypeOptions
                End With

                ' Trap any errors that occur on export
                    'Export the report
                    MessageBox.Show("PDF File Generated from " & fileSource & " into location: " & pdf_path)
                Catch err As Exception
                End Try

            End If
        MessageBox.Show("All pdf files created successfully.")

    End Sub
End Class
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can do this with an application

1. Set the parameters to the report document runtime
2. Get the full report
3. Export the final report into available format

This is pretty long code so I hope you know the object model
I am pasting the section to set the parameetrs in runtime

internal static void CreateParameter(ref ReportDocument report, string ParameterName, object value)
ParameterDiscreteValue  ParameterDiscreteValue;
ParameterValues  ParameterValues;
ParameterFieldDefinition param = report.DataDefinition.ParameterFields[ParameterName];
ParameterValues = new CrystalDecisions.Shared.ParameterValues();
ParameterDiscreteValue = new CrystalDecisions.Shared.ParameterDiscreteValue();      
ParameterDiscreteValue.Value = value;      

After this you set the report document as the viewers datasource
crystalviewer1.reportsource = reportdocument;

Then you do the exporting in code


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vikingg97Author Commented:
This is my first VB.NEt application dealing with CR, so I am going to ask if you could give it to me more basically.  

Unsure what you mean on
--1. Set the parameters to the report document runtime
--2. Get the full report

Also I don't know what you mean about what you mean about knowing the object model and how long it is, and setting the report document as the viewers datasource crystalviewer1.reportsource = reportdocument;  Does that mean in the actual report?  

I don't want to even see the reports while its processing, I just want them to all to export from in a certain folder feeding parameters making a PDF.  

once again I appreciate ahead of time.  vikingg97
The things you are asking has to be done by the application. You have to write and deploy an application. The application has to set the parameters runtime to the report , then display the report to the user. If you dont want the user t osee the report then you can directly send it to the exporting module.

It is not so easy to write this application. First you have to decide what language is available t oyou. What version of crystal do you have and how much does it let you make ru time customizations. Maybe after answering these questions, you will see that you wont be able to do it with your current version and need to uprade
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

vikingg97Author Commented:
I have all the latest technologies available, using CR 10 and VB.NET through VS.NET.  I have already written this application to export the CR to PDF.  This works with a basic crystal report with no parameters pushed in.  I am just wanting to pass parameters into reports then have it convert to a pdf.  

If you can just help me get this done, for example with say 2 reports with parameters, then that is for the most part what I need.  I posted the code above with the working process converting CR into pdf.  Lets say I want a parameter of date and plancode on one report and name and version on the second report.  

Thanks  vikingg97
That is perfect hope you are using c#. The code I posted is C# for parameters. Use that you will be good to go. If you dont undrstand anythind ask me. It works because I have the same technologies and doing it right now

Good luck brother

vikingg97Author Commented:
Like I said I am not using C#, I am using VB.NET.  So the C# code you have posted isn't helping this beginner.  

I said before that if someone could maybe show me an example in VB.NET and just help me get this started, for example with say 2 reports with parameters, then that is for the most part what I need.  I posted the code above with the working process converting simnple CR into pdf.  Lets say I want a parameter of date and plancode on one report and name and version on the second report.  

If someone could help with that part of it just going through 2 reports with those parameters with the code I have already posted, I would appreciate it VERY MUCH. This is kinda urgent.
vikingg97Author Commented:
ANYONE? Help please?
I dont have time to convert the code to It is very similar though. And that code works because I am using in 100 reports.
vikingg97Author Commented:
So that snippet you added works for converting CR to PDF with any multitude of parameters?  
that code sets the parameters of the report in runtime

You have to write little bit more to export t opdf as well.
Glad I could help

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Crystal Reports

From novice to tech pro — start learning today.