Skip to Content
0

Export report in .NET with data in XML file

Oct 13, 2016 at 02:43 PM

190

avatar image
Former Member

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");
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

16 Answers

Best Answer
avatar image
Former Member Oct 19, 2016 at 06:17 AM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Oct 13, 2016 at 02:45 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Nov 01, 2016 at 07:43 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 17, 2016 at 07:25 AM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 19, 2016 at 01:55 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
Dell Stinnett-Christy Oct 19, 2016 at 02:54 PM
0

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-updates-runtime-downloads/

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

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 19, 2016 at 03:49 PM
0

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.

Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 20, 2016 at 02:54 PM
0

Hi Dell,

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

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Oct 20, 2016 at 06:16 PM
0

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

mpl0b.png (8.3 kB)
Share
10 |10000 characters needed characters left characters exceeded
avatar image
Former Member Oct 21, 2016 at 07:15 AM
0

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".


setdatasource.png (30.2 kB)
Share
10 |10000 characters needed characters left characters exceeded