API to get Crystal RPT version - crystal-reports

In the Crystal Studio, I can get to the version of an rpt file by going to Report|Performance Information|Report Definition|File Format Schema.
Is there a way of getting to this same information via the Crystal .NET API?
I can't find it for the life of me.
OLIVER

Check out ReportDocument.ReportClientDocument.MajorVersion and MinorVersion. You'll need to add a reference to CrystalDecisions.ReportAppServer.ClientDoc to access it.
using(var rptDoc = new ReportDocument())
{
rptDoc.Load(path);
Console.WriteLine(rptDoc.ReportClientDocument.MajorVersion);
}

Related

How to retrieve crystal report page(section) name using c#

I have crystal report that I want to separate by the page(section) name and create a pdf file. I've been looking everywhere and have not found and answer. Hopefully someone can help.
`
foreach (ReportDocument pgnName in rpt)
{
exportOpts.ExportFormatOptions = pdfRtfWordOpts;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
destinationOpts.DiskFileName = "C:\\Temp\\report File" + pgnName+ ".pdf";
exportOpts.ExportDestinationOptions = destinationOpts;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
rpt.Export(exportOpts);
}
Couldn't find anything.
The Crystal runtime doesn't provide such an option.
Building report bursting functionality (by page or by group logic) is fairly complex. Your question seems to suggest you are not very familiar with the Crystal Reports object model. So consider 3rd-party Crystal Reports automation tools. Ken Hamady maintains a listing of such tools here. And several of them support report bursting.
Some of these tools also provide an option to export the report to PDF and burst the PDF by page, by bookmark, or by hidden tag formula. That approach may be easier for you to implement in your own code.

How to load an embedded rpt file in crystal report

We have a requirement to load crystal report from embedded resource. In our application each module is a portable area and rpt files are embedded in the assembly. In the crystal report viewer we need to read the embedded rpt file and load the report document using the embedded rpt file.
Thanks in advance,
Anoop X.
Something like this?
private void SetReportSource(String reportPath)
{
object reportPathAsObject = (object)reportPath;
ReportClientDocument reportClientDocument = new ReportClientDocumentClass();
reportClientDocument.Open(ref reportPathAsObject, 0);
crystalReportViewer.ReportSource = reportClientDocument;
}

How to set Jasper to use XSSF?

In a existing system already use jasper 5.0 and as I know it use poi HSSF to generate xls data, but now as the application grow up, the report have a problem with a big count transaction to generate.
I have search for the solution and found POI with XSSF. Because jasper use POI HSSF too, I thinking about to use XSSF inside of JASPER.
Is that possible? and how I could do that? I need to use jasper because it's not possible for now to change the existing app.
To export jrxml generating ooxml XSSF, excel file xlxs
Use the net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter
Example:
JasperPrint jasperPrint = JasperFillManager.fillReport(report, paramMap, connection); //Example of how to get the jasper print
JRXlsxExporter exporter = new JRXlsxExporter();
exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
File outputFile = new File("excelTest.xlsx");
exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(outputFile));
SimpleXlsxReportConfiguration configuration = new SimpleXlsxReportConfiguration();
configuration.setOnePagePerSheet(false); //Set configuration as you like it!!
configuration.setDetectCellType(true);
configuration.setCollapseRowSpan(false);
exporter.setConfiguration(configuration);
exporter.exportReport();
Naturally you need related libraries (poi-ooxml.jar, poi-ooxml-schemas.jar, xmlbeans.jar) in your classpath, they are present in the distribution of jasper report.
The JRXlsxExporter is available since version 4.5 this is the jasper report 5.5.0 API. In version 4 parameters where set instead of properties please see jasperreports-export-to-xlsx-not-xls

Why do I get "Database logon failed" in Crystal Reports when using .NET object as datasource?

I am creating a simple report using a .NET object from my project as datasource, using SetDatasource() method. However, when I run the report I get "Database logon failed" error. This report is not connecting to a DB at all - have I missed something here?
Many thanks,
D.
ADDED:
I guess it will probably help if I include the Controller action. It's a quick and dirty test, not what the final method will look like:
public ActionResult StewardSheets(int showId, int groupId)
{
ReportClass rptH = new ReportClass();
rptH.FileName = DataHelper.getReportFilePath("Test.rpt",this);
NZDSDataContext dataContext = new NZDSDataContext();
var showDetails = (from s in dataContext.Shows
where s.ID == showId
select new StewardSheetModel
{
EventDate = s.EventDate.ToLongDateString(),
Region = s.Region.Name,
ShowTitle = s.Name
}).FirstOrDefault();
List<StewardSheetModel> details = new List<StewardSheetModel>();
details.Add(showDetails);
rptH.SetDataSource(details);
rptH.Refresh();
Stream stream = rptH.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
return File(stream, "application/pdf");
}
FIXED:
D'oh! I used ReportClass instead of ReportDocument. Changed that line, and also use Refresh() since Load() is not a valid method. Now it works just fine!
If you are using ADO.NET DataSets as your datasource, it is possible for the DataSet definition to get out of sync with the definition in the report. Selecting the Database->Verify Database option from the report designer's context menu will often fix this problem.
Also, you will get this error if your report has linked tables and you fail to set the datasource for one of the tables. The fix is either to remove the table from the report, or set it's datasource correctly.
For example, if your report has a Customers table and an Orders table linked together on some key you will need to set the datasource for both tables. If you forget and set only one, you will get a "Database logon failure" error which is fairly misleading.
// Create a new customer orders report.
CustomerOrdersReport report = new CustomerOrdersReport();
// Get the report data.
DataTable customersTable = getCustomersData();
DataTable ordersTable = getOrdersData();
// Set datasources.
report.Database.Tables["Customers"].SetDataSource(customersTable);
report.Database.Tables["Orders"].SetDataSource(ordersTable ); // Don't forget this line like I did!!
Please try, Right-Click on Report -> Database-> Verify Database.
If dialog box appears, locate your DataSet .xsd file (e.g DataSet1.xsd) and Apply.
My problem solved in this way.
I started getting the notorious "database logon failed" error on a Windows Server 2016 machine after the July 2018 windows server updates. The report ran fine in Visual Studio 2017 on my dev machine, but not in IIS on Windows Server 2016 in production.
After a day of investigation, I installed the Microsoft OLE DB Driver for SQL Server on my development machine - https://learn.microsoft.com/en-us/sql/connect/oledb/oledb-driver-for-sql-server?view=sql-server-2017. I created a report connection in the Crystal report database expert using the MSOLEDBSQL provider. I had to install the Microsoft OLE DB Driver for SQL Server on the production Windows Server 2016 machine as well.
It turns out Microsoft has decided to deprecate the Microsoft OLE DB Provider for SQL Server. This and the native client no longer seem to work with Crystal Reports.
I was struggling with this error for a couple of days. I have a .NET webforms project which uses CrystalReportViewer to load a Crystal Report. Instead of the report loading, I kept getting "Database logon failed".
I opened the RPT file in Crystal Report Designer and went to Database -> Verify Database
This gave me a more specific error. FINALLY!!!
I tracked down the XSD file, moved it to the right location and BOOM
I started getting this dialog popping up after I changed the name of the .NET object my reports were referring to. To get rid the dialog, I had to ensure that none of my report sections or fields referred to the old name of the .Net object which was easy to spot. The fix for me was using the rename function in the Database Expert for the report.
Fixed by using the appropriate class: ReportDocument instead of ReportClass.
One of the reason of this error is, when u pass null object to a sub report
....SetDataSource(data) , where data is null
I had to do write the below line of code to get rid of the "Database login error"
CrystalDecisions.Shared.TableLogOnInfo li;
li.ConnectionInfo.IntegratedSecurity = false;
Mine did it when I was sending in a DataSet instead of a DataTable.
ReportDocument.SetDataSource(dataset.Tables[0]);
In my case i forget to set datasource to a datatable.
something like this
rpt.Database.Tables("Account").SetDataSource(CType(DataSource.Account, DataTable))
Use native client Connection Version 10.
I hade the same problem and it was due to the fact that I accidentally added anoher DataTable with the same name.
var ds = new OrderDetail();
var dt = new OrderDetail.ResultDataTable();
//fill dataset here
ds.Tables.Add(dt);
After setting that DataSet as datasource I got the login failed error when exporting the report.
I then added a line to remove the DataTable before adding the new DataTable:
ds.Tables.Remove(dt.TableName);

Crystal Report .NET font changing

I've designed a crystal report that will be sent to a specific (barcode) printer through a web interface. Allowing the report to be generated in the standard crystal report viewer was causing issues, so I am now using the code-behind to send the report directly to the printer.
ReportDocument Report = new ReportDocument();
ParameterDiscreteValue Order = new ParameterDiscreteValue();
Order.Value = Convert.ToInt32(txtOrder);
Report.Load(reportPath);
Report.SetParameterValue("OrderNo", Order);
PageMargins margins;
margins = Report.PrintOptions.PageMargins;
margins.bottomMargin = 0;
margins.leftMargin = 0;
margins.rightMargin = 0;
margins.topMargin = 0;
Report.PrintOptions.ApplyPageMargins(margins);
Report.PrintOptions.PrinterName = "\\\\printserver\\Zebra Z6M Plus (300dpi)";
Report.PrintToPrinter(1, false, PageNum, PageNum);
Report.Close();
When printed from the designer (CRXI) everything works fine but when the web interface sends the job to a printer (any printer) it changes the font to Times New Roman which messes up all of the field sizes. If I use the standard .NET report viewer it uses the correct font, so I'm pretty sure the change is being caused by creating/using the ReportDocument.
How can I send the report directly to a print without it defaulting the fonts back to Times New Roman?
This idea occured to me:
Instead of sending the report straight from Crystal to the printer, what if you use some kind of middleman, i.e. export the .rpt to .pdf first, then print the PDF?
(Yes, it would be a very "wooden tables" tables approach, but if it works, it works.)
While it seemed like the special font I was using had been included on every server imaginable, I was never able to get it to work through the web interface.
I ended up finding a standard windows font that mostly suited the needs of this project and have given up on trying to beat this problem.
You need use RAS SDK API. Crystal Reports for Visual Studio 2010 (v13) include this api. (This code don't work in Crystal Reports for Visual Studio 2005... I don't have info about other versions)
Add this references to your existing code:
CrystalDecisions.ReportAppServer.ClientDoc
CrystalDecisions.ReportAppServer.Controllers
CrystalDecisions.ReportAppServer.ReportDefModel
And use this code (VB... sorry)
Using rpt As New CrystalDecisions.CrystalReports.Engine.ReportDocument
rpt.Load(file, CrystalDecisions.[Shared].OpenReportMethod.OpenReportByTempCopy)
rpt.SetDataSource(_ReportSource)
Dim options As New CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions
options.Collated = _Collate
options.NumberOfCopies = _Copies
' TODO: Implement_startPageN and _endPageN
Dim optPrint As CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions
optPrint = rpt.ReportClientDocument.PrintOutputController.GetPrintOptions
optPrint.PrinterName = _PrinterName rpt.ReportClientDocument.PrintOutputController.ModifyPrintOptions(optPrint)
rpt.ReportClientDocument.PrintOutputController.PrintReport(options)
rpt.Close()
End Using
I was trying to change Crystal Report Font according to data that will be shown on the report.
I use Formate Formula to change the font using flags Condition.
if({?vIsRightToLeft}=true)then
"Attari Font"
Else
"Arial"