cancel
Showing results for 
Search instead for 
Did you mean: 

Export report in .NET with data in XML file

Former Member
0 Kudos

Hello,

I have a report with the data in a XML file. In the report definition, the link with XML file is relative path, only "myxmlfile.xml" and "myxsdfile.xsd". In my code, I want load this report and exported to the disk in PDF file or to printer.

If I don't launch the preview the report before in the Crystal Designer, my code don't work and I have a error "CrystalDecisions.CrystalReports.Engine.LogOnException : Echec de connexion à la base de données" : failed to connect to the database.

Have you got any solution , please ?

This is my code :

ReportDocument rptXml = new ReportDocument();
rptXml.Load("myrptfile.rpt");
rptXml.ExportToDisk(ExportFormatType.PortableDocFormat, "res.pdf");

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Matthieu,

I tested the following code on my development machine:

ReportDocument rdoc = new ReportDocument();
rdoc.Load(Server.MapPath("CrystalReport1.rpt"));
rdoc.ExportToDisk(ExportFormatType.PortableDocFormat, "c:\res.pdf");

but got the following error:

Illegal characters in path.

Then I changed the last line as follows (changed backslash to forward slash):

rdoc.ExportToDisk(ExportFormatType.PortableDocFormat, "c:/res.pdf");

and the pdf generated successfully.

You can also test with a blank myrptfile.rpt to check if there is an issue with connecting to the database or exporting the report to disk.

Regards,

Aziz

Answers (15)

Answers (15)

0 Kudos

Hi Matthieu,

I just logged an issue with R&D for Relative Pathing, it may be fixed in the next SP. It's getting close to code close time so not sure if they can get it into SP 19.

See this KBA - https://launchpad.support.sap.com/#/notes/2397203

Don

0 Kudos

Hi Matthieu,

I just logged an issue with R&D for Relative Pathing, it may be fixed in the next SP. It's getting close to code close time so not sure if they can get it into SP 19.

See this KBA - https://launchpad.support.sap.com/#/notes/2397203

Don

Former Member
0 Kudos

Hi everybody,

you don't have a solution for me?

I want just launch the preview with the code.

Or have you got an other idea to change the path of XML file of data source in the report without using Java library ?

Thanks.

0 Kudos

Ah yes of course...

Only works using the fully qualified path, has always been that way.

Don

Former Member
0 Kudos

Hi Don,

I don't understand everything in your last post, but I use the unqualified paths because I develop a application who takes a XML data files, who are generated by a other application and it's possible to have many edition in the same time. In the first time, I wanted to duplicate the report for each edition and to change the path in this new report. But to change the path of data fil in the report, we have to use a Java module. And I don't want use Java module.

So, I tried to put a unqualified paths in report and with the Crystal designer, it works. And when I code this method, only reports, that have had the preview launched and were saved, work.

You understand ? And sorry for my english.

Matthieu.

0 Kudos

Hi Matthieu,

Ah, you are using the Legacy XML driver, so correct, you can't set same as....

I did some testing and you are correct, it cannot resolve an unqualified path to the XML file. That legacy driver from what I can recall always required a fully qualified path to the DB file.

When the engine opens a report it makes a temp copy of it in the C:\Users\%NAME%\AppData\Local\Temp folder. This is also where the data fie is expected to be. Now this works if you can set the Same As... feature but it does not work for that legacy driver.

It needs to be fully qualified.

So question now is WHY do you want to use unqualified paths?

Don

Former Member
0 Kudos

Hi Don,

thanks, but the fully output location don't works.

I work on Visual Studio 2015 and Crystal Report XI R2. The version of Crystal assemblies is 13.0.2000.0 and the version of the runtime is v2.0.50727.

Is it possible to launch the preview in the code ?

Matthieu.

Former Member
0 Kudos

Hi Don,

your solution doesn't work in my example, because I use a XML file for database and I haven't this action :"Same as Report".

0 Kudos

Open the Report in CR Designer, go to Set Database... and right click on the Server location and select Same As...

That should remove the fully qualified location.

With SP 18 it should now look in the original location of the report and not the \temp folder.

And for the report location you need to add a slash:

rdoc.Load(Server.MapPath("\CrystalReport1.rpt"));

Don
Former Member
0 Kudos

Hi Dell,

the latest version of the SDK doesn't works in my example.

Former Member
0 Kudos

Hi Dell,

thank you, I downloads the last version of SDK and I will test after.

But, why all is right when my report is saved after preview ?

Matthieu.

DellSC
Active Contributor
0 Kudos

The Crystal XI r2 SDK will NOT work with Visual Studio 2015!. You need to do an update install of Crystal and uninstall the .NET SDK.

After that's done, you can go here to download the latest version of the SDK: https://blogs.sap.com/2010/12/07/sap-crystal-reports-developer-version-for-microsoft-visual-studio-u...

Use the "Install Executable" for integration into Visual Studio. DO NOT install any of the runtimes on the development workstation. The runtime installs are for use only when deploying your application.

-Dell

Former Member
0 Kudos

Hi Aziz,

thank you for your post, but I still have the problem. I want to share RPT files but I can't join the files or a ZIP file.

So, you can find my files :

https://www.dropbox.com/sh/5hmdruc7yny30g0/AACnxbJBOphEFqX_YYytRTKSa?dl=0

Thanks again.

Former Member
0 Kudos

Hi Don,

the full output location don't work.

I use Visual Studio 2015 and Crystal Report XI R2. I develop a Windows application.

Thanks.

0 Kudos

Hi Mathieu,

What SDK and version are you using?

Windows or WEB app?

Try fully qualifying the output location also, like "c:\res.pdf"

Don