?
Solved

Passing parameters in VB.Net that converts Crystal Report to pdf

Posted on 2004-11-03
7
Medium Priority
?
778 Views
Last Modified: 2008-02-01
I have a VB.NET windows app, that has a button goes out and converts CR to PDF, and I don't view it.  This works fine.  I am wanting now to have a parameter passed into this CR pulling out of a table, passed to my report then generated into a pdf.  Say that the field in the table is strVariable.

Here is my code that does the conversion, could someone please help me and show me where I would put in this passing of a parameter.  Like where to put it in my VB.NET code?  Thanks so much...

 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
                Try
                    'Export the report
                    CrReport.Export()
                    MessageBox.Show("PDF File Generated from " & fileSource & " into location: " & pdf_path)
                Catch err As Exception
                    MessageBox.Show(err.ToString())
                End Try

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

    End Sub
0
Comment
Question by:vikingg97
  • 3
  • 2
  • 2
7 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 12486572
You put the code somewhere before you call the export routine.

I would put them after you set the export options.

mlmcc
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12487422
I forgot to put in my question how to to get this variable out of a table and to put it into a parameter within the CR?  

Say if the field in the table is strVariable?

I have looked around but haven't found any definitive answers.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 12489511
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 10

Expert Comment

by:ebolek
ID: 12493553
So you want to set  aparameter in runtime and then export the final diocument to pdf right? I have c3 code for you. Can you convert it to vb.net
0
 
LVL 1

Author Comment

by:vikingg97
ID: 12493684
I can always try to convert it I suppose ebolek.  Remember this is not a web application.  This is a VB.NET windows application.  
0
 
LVL 10

Accepted Solution

by:
ebolek earned 2000 total points
ID: 12494212
That is fine. Workd for windows.

Here is the code.

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;      
                  ParameterValues.Add(ParameterDiscreteValue);
                  param.CurrentValues.Clear();
                  param.DefaultValues.Clear();  
                  param.ApplyCurrentValues(ParameterValues);
            }
0
 
LVL 10

Expert Comment

by:ebolek
ID: 12523461
Glad I could help

Regards
Emre
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question