简体   繁体   中英

Crystal Reports for Visual Studio 2017 - Exporting a Report

I am creating a c# application to export reports using existing crystal report documents. I have been successful, except for specific instance. When exporting to a file (PDF, xls) I am getting a windows folder dialog to name and locate the export (even though I am defining the format type, location, and name of the file. Is there a way to preclude this windows folder dialog from showing up, and just deposit the export in the described location. Below is the code which is exporting the crystal report. Any help would be greatly appreciated.

static void Main(string[] args)
{
    ReportDocument myReportDocument = new ReportDocument();
    CrystalReport1 rpt = new CrystalReport1();
    CrystalReportViewer cView = new CrystalReportViewer();
    ExportOptions crExportOptions = new ExportOptions();
    PdfFormatOptions crFormatTypeOptions = new PdfFormatOptions();
    DiskFileDestinationOptions crDiskFileDestinationOptions = ExportOptions.CreateDiskFileDestinationOptions();

    myReportDocument.Load(args[1]);
    myReportDocument.DataSourceConnections[0].SetConnection(args[5], args[5], "Admin", "");
    myReportDocument.SetParameterValue(rpt.Parameter_ADDTransformerID.ParameterFieldName.ToString(), args[2]);
    myReportDocument.SetParameterValue(rpt.Parameter_ProjectName.ParameterFieldName.ToString(), args[3]);
    crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
    crDiskFileDestinationOptions.DiskFileName = args[4];
    crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
    crExportOptions.ExportDestinationOptions = crDiskFileDestinationOptions;
    cView.ReportSource = myReportDocument;

    switch (args[0])
    {
        case "0" :
            cView.PrintReport();
            break;
        case "1" :
            cView.PrintReport();
            break;
        case "2" :
            cView.ExportReport();
            break;
    }

You're creating a new ExportOptions -object instead of assigning the options to the actual ReportDocument -object.

Changing this line

ExportOptions crExportOptions = new ExportOptions();

to

ExportOptions crExportOptions = myReportDocument.ExportOptions;

should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM