Skip to Content

Crystal Report

Dear Experts,

I have a crystal report that requires some parameters. and after giving the parameters it populates the data as per the parameters. Now I want that these parameters should be passed by code and after that this report should be exported into PDF Format.

Is that possible to do ?

Plz help.


Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • Best Answer
    May 21, 2015 at 06:07 AM


    Here is a sample how to do it:

    ReportDocument cryRpt = new ReportDocument();

    string path = System.Windows.Forms.Application.StartupPath + @"\Customer Statement.rpt";


    cryRpt.SetDatabaseLogon(ConfigurationSettings.AppSettings["sqluname"], ConfigurationSettings.AppSettings["sqlpass"], ConfigurationSettings.AppSettings["sqlserver"], ConfigurationSettings.AppSettings["dbname"], false);

    cryRpt.SetParameterValue("CardCode@Select * from OCRD where Cardtype = 'C'", "C0015");

    string FromDate = "20150103";

    SAPbobsCOM.SBObob objBridge = (SAPbobsCOM.SBObob)SBO_Company.GetBusinessObject(BoObjectTypes.BoBridge);

    string ValidFromDate = FromDate;

    DateTime FromDt = Convert.ToDateTime(objBridge.Format_StringToDate(ValidFromDate).Fields.Item(0).Value);

    string ToDate = "20150430";

    string ValidToDate = ToDate;

    DateTime ToDt = Convert.ToDateTime(objBridge.Format_StringToDate(ValidToDate).Fields.Item(0).Value);

    cryRpt.SetParameterValue("fromdate", FromDt);

    cryRpt.SetParameterValue("Todate@", ToDt);

    ExportOptions CrExportOptions;

    DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();

    PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();

    CrDiskFileDestinationOptions.DiskFileName = System.Windows.Forms.Application.StartupPath + @"\Mail" + "25" + ".pdf";

    CrExportOptions = cryRpt.ExportOptions;


    CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;

    CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;

    CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;

    CrExportOptions.FormatOptions = CrFormatTypeOptions;



    Hope it helps.

    Thanks & Regards

    Ankit Chauhan

    Add comment
    10|10000 characters needed characters exceeded

  • May 21, 2015 at 05:57 AM

    Hi Kuldeep,

    Your requirement is very much possible. First you need to use references

    CrystalDecisions.CrystalReports.Engine & CrystalDecisions.Shared.

    Then using ReportDocument and ExportOptions you can achieve what you need.

    Hope it helps.

    Thanks & Regards

    Ankit Chauhan

    Add comment
    10|10000 characters needed characters exceeded