SHARE
TWEET

Untitled

a guest Aug 9th, 2017 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CrystalDecisions.CrystalReports.Engine;
  6. using CrystalDecisions.Shared;
  7.  
  8. namespace ConsoleApplication1
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             // exports crystal report
  15.  
  16.             string report_name = "";
  17.             string export_path = "";
  18.             string username = "";
  19.             string password = "";
  20.  
  21.             if (args.Count() < 2)
  22.             {
  23.                 Console.WriteLine("Error. Usage: Crystal.exe \"c:\\input.rpt\" \"c:\\output.pdf\" \"username\" [opt] \"password\" [opt]");
  24.                 return;
  25.             }
  26.  
  27.             report_name = args[0];
  28.             export_path = args[1];
  29.             if (args.Count() > 2) username = args[2];
  30.             if (args.Count() > 3) password = args[3];
  31.  
  32.             Console.WriteLine(string.Format("RN: {0} EXP: {1} UN: {2} PW:{3}", report_name, export_path, username, password));
  33.  
  34.             //above
  35.             //string reportName = "output"; // *Not Required
  36.             //string exportPath = "C:\\Users\\Tom\\Documents\\" + reportName + ".pdf"; // *Not Required
  37.  
  38.  
  39.             ReportDocument crReportDocument = new ReportDocument();
  40.  
  41.             //Load the report and set its parameters
  42.  
  43.             crReportDocument.Load(report_name);
  44.             crReportDocument.SetDatabaseLogon(username, password);  
  45.             //crReportDocument.SetParameterValue("@FromDate", dtFrom);
  46.             //crReportDocument.SetParameterValue("@ToDate", dtTo);
  47.  
  48.             // Export options
  49.             ExportOptions crExportOptions;
  50.             DiskFileDestinationOptions crDestOptions = new DiskFileDestinationOptions();
  51.             crDestOptions.DiskFileName = export_path;
  52.             crExportOptions = crReportDocument.ExportOptions;
  53.             crExportOptions.DestinationOptions = crDestOptions;
  54.             crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
  55.             crExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
  56.  
  57.             // Export
  58.             crReportDocument.Export();
  59.  
  60.  
  61.         }
  62.     }
  63. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top