on 11-18-2016 4:43 PM
Hello,
I'm trying to export a Crystal Report using RAS and the CRforVS_13_0_18 SDK for .Net using WPF and Visual Studio 2010. The export fails on this series of code (last line):
rasReportExportFormat = CrReportExportFormatEnum.crReportExportFormatPDF; rasPrintOutputController = doc.PrintOutputController;
ByteArray tempByteArray = rasPrintOutputController.Export(rasReportExportFormat, 0);
The error message is "The system cannot find the path specified" in source rptcontrollers.dll with error code -2147467259.
I believe the logic is fine because I'm able to use the same logic and settings in Java and it pulls the report with no problems in less than a second. I would assume that the issue takes root in the connection to the database, but unless I'm missing some settings for Oracle, it seems like the code is correct.
Here is the operation that tries to export the report:
private void exportRASReport()
{
//Crystal Server
String sCrystalHost = Properties.Settings.Default.sCrystalHost;
//Report template
//The .rpt file has to exist on the server where the Crystal engine is
String reportName = Properties.Settings.Default.sReportPath;
Object reportPath = (Object)reportName;
//Database Settings
String sDBHost = Properties.Settings.Default.sDBHost;
String sDBSID = Properties.Settings.Default.sDBSID;
String sDBUser = Properties.Settings.Default.sDBUser;
String sDBPass = Properties.Settings.Default.sDBPass;
//Report parameters
Dictionary<String, Object> parameters = new Dictionary<String, Object>();
//Examples
parameters.Add("SPUser", "Coordinator");
parameters.Add("SPTimeZone", "GMT");
parameters.Add("SPQueryHeading", "Whatever!");
ReportClientDocument doc = new ReportClientDocument();
try
{
doc.ReportAppServer = sCrystalHost;
doc.Open(ref reportPath, (int)CdReportClientDocumentOpenOptionsEnum.cdReportClientDocumentOpenAsReadOnly);
//Set up Propert Bags for connecting to DB
PropertyBag logonProps = new PropertyBag();
logonProps.Add("Server", sDBSID);
PropertyBag pBag = new PropertyBag();
pBag.Add("QE_ServerDescription", sDBSID);
pBag.Add("QE_SQLDB", true);
pBag.Add("QE_DatabaseType", "Oracle Server");
pBag.Add("Database DLL", "crdb_oracle.dll");
pBag.Add("QE_LogonProperties", logonProps);
//Create the ConnectionInfo object
ConnectionInfo ci = new ConnectionInfo();
ci.Attributes = pBag;
ci.UserName = sDBUser;
ci.Password = sDBPass;
ci.Kind = CrConnectionInfoKindEnum.crConnectionInfoKindCRQE;
//replace old data source with new datasource
DatabaseController databaseController = doc.DatabaseController;
ConnectionInfos connectionInfos = databaseController.GetConnectionInfos(null);
ConnectionInfo oldConnectionInfo = connectionInfos[0];
databaseController.ReplaceConnection(oldConnectionInfo, ci, null, (int)CrDBOptionsEnum.crDBOptionUseDefault + (int)CrDBOptionsEnum.crDBOptionDoNotVerifyDB);
//set parameters for the report
foreach (KeyValuePair<String, Object> kvp in parameters)
{
doc.DataDefController.ParameterFieldController.SetCurrentValue("", kvp.Key.ToString(), kvp.Value.ToString());
}
//Set filter for a specific table and record
String sRecordNumber = "12345";
String sFilterText = "{*TableName*.id} = " + sRecordNumber; //Table name removed for privacy reasons
Filter iFilter = doc.DataDefController.DataDefinition.RecordFilter;
iFilter.FilterItems.RemoveAll();
iFilter.FreeEditingText = sFilterText;
doc.DataDefController.RecordFilterController.Modify(iFilter);
PrintOutputController rasPrintOutputController;
CrReportExportFormatEnum rasReportExportFormat;
rasReportExportFormat = CrReportExportFormatEnum.crReportExportFormatPDF;
rasPrintOutputController = doc.PrintOutputController;
ByteArray tempByteArray = rasPrintOutputController.Export(rasReportExportFormat, 0); //this is the line that causes the error
Byte[] byteStreamOutput = tempByteArray.ByteArray;
String sSavePathName = @"C:\Output\export.pdf";
FileStream fs = new FileStream(sSavePathName, FileMode.Create, FileAccess.ReadWrite);
int maxSize = byteStreamOutput.Length;
fs.Write(byteStreamOutput, 0, maxSize);
fs.Close();
}
catch (Exception e)
{
System.Windows.Forms.MessageBox.Show(e.Message);
}
finally
{
if (doc != null)
try
{
if (doc.IsOpen)
{
doc.Close();
}
}
catch (Exception e) { }
}
}
Hi Rex,
Using CR for VS you need to open the reports with the engine, then if you want to use RAS convert the ClientDoc to ReportClientDoc.
Download the sample app I included in in the Printer or Parameter app in KBA 2163438 and 2281780.
It has examples of how to open a report and convert to RAS.
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rex,
Don't browse to the CR Assemblies, use the Add Reference feature in VS and select them from the GAC:
This one is definitely not a Version 13 dll:
CrystalDecisions.Enterprise.Viewing.ReportSource.dll CrystalDecisions.ReportAppServer.ClientDoc.dll
And you likely don't need this one:
CrystalDecisions.ReportAppServer.CubeDefModel.dll CrystalDecisions.ReportAppServer.DataDefModel.dll
And you did not include the Controller, just like the error indicates:
using CrystalDecisions.ReportAppServer.Controllers;
Also, I recommend using the WinForm Viewer rather than the WPF viewer. It's much more mature and has a lot more features available.
Don
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, Don.
Thank you very much for your response!
I've created a new Windows Forms project, copied in the same source code (in the .txt file), added the assemblies via Project > Add Reference (from the GAC). I've attached a screenshot of the added references, and here are all the 'using's in my my project:
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportAppServer.ReportDefModel;
I am getting the same error message at the same line of code:
Message = "The system cannot find the path specified.\r"
StackTrace = " at CrystalDecisions.ReportAppServer.Controllers.ISCRPrintOutputController.Export(CrReportExportFormatEnum exportFormat, Int32 Reserved)\r\n at Crystal_TW_Printer_WFA.Form1.btnReports_Click(Object sender, EventArgs e) in ...
By the way, I don't want to view the report in the .Net application. I simply want to export the report as a PDF file and save it to my computer. I'm not sure if that has an impact on your response.
Thanks again!
I really appreciate your help.
-Rex
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.