Hello,
Last month our company upgrade from Crystal 11 to Crystal 14.1.2.1121
This upgrade broke the existing VB script which was used to generate nightly reports on each active job. If I understand correctly, the new version of Crystal can no longer be called from VB script. I do not own a copy of Visual Studio. What are my choices for re-writing this VB program?
It seems like I should be able to use a program called CS-Script which is build on top of Microsoft Common Runtime Library, but I don't have any documentation on how to get Crystal working without Visual Studio. I do not need to view the report.. I simply want to export it to a PDF.
This is what I have so far in my CS-Script:
using System;
using System.Web;
using System.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
public class Script
{
const string usage = "Usage: Export Crystal Report";
static public void Main(string[] args)
{
//System.Diagnostics.Debug.Assert(false) ;
if (args.Length == 1 && (args[0] == "?" || args[0] == "/?" || args[0] == "-?" || args[0].ToLower() == "help"))
{
Console.WriteLine(usage);
}
else
{
// apparently the viewer object is only available in Visual Studio
//CrystalReportViewer crystalReportViewer1 = new CrystalReportViewer();
ReportDocument cryRpt = new ReportDocument();
cryRpt.Load(@"JobInfoForm.rpt");
//crystalReportViewer1.ReportSource = cryRpt;
//cryRpt.InitReport;
//cryRpt.ExportToDisk(ExportFormatType formatType, String fileName);
cryRpt.ExportToDisk(31, @"C:\share\jif.pdf");
MessageBox.Show("Export Finished");
}
}
}
This code fails with the following two errors when I try to run it:
c:\Share\crystal_JIF3.cs(30,13): error CS1502: The best overloaded method match for 'CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToDisk(CrystalDecisions.Shared.ExportFormatType, string)' has some invalid arguments
c:\Share\crystal_JIF3.cs(30,33): error CS1503: Argument 1: cannot convert from 'int' to 'CrystalDecisions.Shared.ExportFormatType'
Here is the old VB Script which no longer works as of the latest version of Crystal.
Sub Crystal_export(jobno)
'Called from exp_Job The purpose is to Export JobInfo Report
'Is called for every Job.
Dim Appn
Dim Report
Dim FSO
Dim Path
Dim ReportName
Dim OutputFile
Dim DiskFilePath
Dim ParamOne
Dim Param1Name
Dim dbproperties
Dim FileFormat
Dim FullOutputPath
On Error goto 0
'**********************************************************************************************
'Define variables
'**********************************************************************************************
ReportName = "JobInfoForm.rpt"
DiskFilePath = "C:\Share\JobInfo\"
OutputFile = jobno
FileFormat = ".PDF"
Param1Name = "Job"
ParamOne = jobno 'ex:"150-14-4003"
'**********************************************************************************************
'Open report
'**********************************************************************************************
Set FSO = CreateObject("Scripting.FileSystemObject")
Set Appn = CreateObject("CrystalRuntime.Application")
Set Report = Appn.OpenReport(ReportName)
Path = OutputFile '& "_" & Year(Now) & Month(Now) & Day(Now) &
Hour(Now) & Minute(Now) & Second(Now)
FullOutputPath = DiskFilePath & Path & FileFormat
'**********************************************************************************************
'Report parameters
'**********************************************************************************************
Set dbproperties = Report.Database.Tables.Item(1).ConnectionProperties
dbproperties("User ID") = "??"
dbproperties("Password") = "??"
Report.DiscardSavedData
Report.ParameterFields.GetItemByName("Job").AddCurrentValue Left(ParamOne,11)
Report.EnableParameterPrompting = False
'**********************************************************************************************
'Report Format & Export
'**********************************************************************************************
'Report.ExportOptions.HTMLFileName = FullOutputPath
Report.ExportOptions.FormatType = 31
'FormatType: 31 = PDF, 36 = XLS, 14 = DOC, 32 = HTML40, 4 =RichText
Report.ExportOptions.DestinationType = 1 ' crEDTDiskFile
Report.ExportOptions.PDFExportAllPages = True
Report.ExportOptions.DiskFileName = FullOutputPath
Report.Export (False)
'**********************************************************************************************
'Object clean-up
'**********************************************************************************************
Set FSO = Nothing
Set Appn = Nothing
Set Report = Nothing
End Sub
Thank you for your time and consideration
-Rob