Skip to Content
avatar image
Former Member

Export report in .NET with data in XML file

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");
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

16 Answers

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

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 13, 2016 at 02:45 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 01, 2016 at 07:43 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 17, 2016 at 07:25 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 19, 2016 at 01:55 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 19, 2016 at 02:54 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 19, 2016 at 03:49 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 20, 2016 at 02:54 PM

    Hi Dell,

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

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 20, 2016 at 06:16 PM

    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
    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 21, 2016 at 07:15 AM

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

    Add comment
    10|10000 characters needed characters exceeded