on 2016 Dec 21 2:06 PM
Public Function CreateReport(lxReportXml As String, lcFileName As String, lcReport As String) As Boolean
Dim rd As ReportDocument = Nothing
Dim llError As Boolean = False
Dim IsRoutineSuccessful As Boolean = False
Dim lcFileNameTo As String = String.Empty
Dim ds As New DataSet()
Dim filePath As String = lxReportXml
ds.ReadXml(filePath, XmlReadMode.Auto)
If lcFileName = "" Then
writelog("[ERR] No PDF file specified")
llError = True
End If
If lxReportXml = "" Then
writelog("[ERR] No XML file specified")
llError = True
End If
If lcReport = "" Then
writelog("[ERR] No Crystal Report file specified")
llError = True
End If
If llError = False Then
Dim strErrorMessage As String = String.Empty
#If DEBUG Then
Dim strReportPath As String = CrystalFilesTesting + lcReport + ".rpt"
#Else
Dim strReportPath As String = CrystalFiles + lcProcName + ".rpt"
#End If
If Not (File.Exists(strReportPath)) Then
writelog("[ERR] Crystal Report File [" + strReportPath + "] not found.")
IsRoutineSuccessful = False
Else
rd = New ReportDocument()
If True Then
Try
rd.Load(strReportPath)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rd.SetDataSource(ds)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
rd.ExportToDisk(ExportFormatType.PortableDocFormat, lcFileName)
Catch ex As Exception
writelog("[ERR] Unable to create file [" + lcFileName + "]. Error: " + ex.ToString)
IsRoutineSuccessful = False
Finally
writelog("File [" + lcFileName + "] created Successfully")
rd.Close()
rd.Dispose()
#If DEBUG Then
lcFileNameTo = "\\WGO\sys2\HOME\wilbir\wilbirmail\WilbirHR\EmplAppPDF\Testing\" + lcLastName + "_" + lcPDFDate + ".pdf"
#Else
lcFileNameTo = "\\WGO\sys2\HOME\wilbir\wilbirmail\WilbirHR\EmplAppPDF\" + lcLastName + "_" + lcPDFDate + ".pdf"
#End If
File.Copy(lcFileName, lcFileNameTo, True)
IsRoutineSuccessful = MailSend(lcFileName)
End Try
End If
End If
End If
Return IsRoutineSuccessful
End Function
The line... rd.SetDataSource(ds) throws many errors, however if I go to the Crystal Report and set the Data Source manually, it works without error. I have updated to Crystal Reports 2016 without any resolution.
Ah, you are missing this from your app.config file:
<startup useLegacyV2RuntimeActivationPolicy="true">
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is a known error. You need to update your app.config file by replacing "<startup>" with "<startup useLegacyV2RuntimeActivationPolicy="true">".
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pat,
Try using .ReadSchema rather than .Auto, not sure what that one does.
CR requires the XML to have the Schema included with the XML file.
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did get a new error... (cut it down to one)...
An unhandled exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'file:///C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\win32_x86\dotnet1\crdb_adoplus.dll' or one of its dependencies. The system cannot find the file specified.
This looks like it is probably a reference missing. Am I close?
You have to load the data into the dataset before you assign the dataset as the report source.
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The Dataset (ds) is loaded 27 lines before it is designated as the report source for the report document (rd) with
rd.SetDataSource(ds)
What am I missing in this? I create a Dataset, load data into it from xml, and then try to assign it as report source. You may well be seeing a problem, I am not.
I don't see that you're every loading any data into the data set before you assign it to the report. "Dim ds As NewDataSet()" just creates a new, empty dataset - there are no tables or data in it for the report to connect to.
-Dell
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
67 | |
10 | |
8 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.