private bool disposedValue = false; // To detect redundant calls /// <summary> /// Clean up Crystal ReportDocument /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { CrystalReportDocument?.Close(); CrystalReportDocument?.Dispose(); AccpacReport.Dispose(); Session?.Dispose(); } disposedValue = true; } }
protected virtual void ExportReportUsingCrystal(string reportPath, ExportFormatType reportType) { DiskFileDestinationOptions destinationOptions = new DiskFileDestinationOptions(); destinationOptions.DiskFileName = reportPath; //CrystalReportDocument.set //CrystalReportDocument.SetDatabaseLogon("loc", "winter08", "CTS_DEVL", null,true); CrystalReportDocument.SetDataSource(ReportData); if (CrystalReportDocument.Subreports.Count > 0) { PopulateSubreportData(CrystalReportDocument); } SetReportParameters(); //Set the datasource for the report CrystalReportDocument.ExportOptions.DestinationOptions = destinationOptions; CrystalReportDocument.ExportOptions.ExportFormatType = reportType; CrystalReportDocument.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile; //Assign the export options so we can export to pdf file //destinationOptions.DiskFileName = reportPath; //Export the report try { //CrystalReportDocument.SetDatabaseLogon //CrystalReportDocument.ExportToStream(CrystalReportDocument.ExportOptions.ExportFormatType); CrystalReportDocument.Export(); } catch (Exception ex) { throw new ApplicationException("An unexpected error occurred trying to export the report: " + ex.ToString()); } }