Exporting from Crystal Reports to PDF, Word, Excel and HTML

Crystal Reports is a welcome subjects for blog posts. I still do like the product, my users are very happy with the results, the report editor is not that bad to work with and the components integrate well into a solution. But Crystal documentation is an absolute disaster. I wanted to add some functionality to my basic export routine. The only thing was adding export to Excel and to html. This functionality is present in the basic Crystal installation but how to use it is something which took me really a lot of Googling. The answers were not on the Crystal site but in the dungeons of the usenet. Let me share what I found.

On of the things I learned is that you have to Close() a report after exporting. This was not in the official Crystal example. I havn't measured the effect but it doesn't harm.

Exporting to Excel turned out to be just a matter of setting the right content type. This type turned out to be application/vnd.ms-excel. I had expected application/msexcel, as a nice sibling to application/msword. Exporting to Excel has some extra format options but you can do without them for a basic export. I'll leave these for another post.

To get the exporting to html to work took some things which are next to ridiculous, but I got it working. You have to set some format options. In these options you set the root directory and the filename. This directory-filename pair should be identical to the export filename passed to the report. The result will be an html formatted report, but in a "slightly" different location. To find the result you have to do some tricks. When Crystals creates a report is does create a temporary .rpt file. This file is stored in the windows\temp dir, it's name is a guid. When Crystal creates the exported report it creates a directory in the root directory supplied with the name of this guid. In this directory the report will be created, using the filename supplied. Thank goodness the name of the temporary file is available in the FilePath property of the report. This snippet demonstrates the workaround:

string[] fp = selectedReport.FilePath.Split("\\".ToCharArray());
string leafDir = fp[fp.Length-1];
// strip .rpt extension
leafDir = leafDir.Substring(0, leafDir.Length – 4);
tempFileNameUsed = string.Format("{0}{1}\\{2}", tempDir, leafDir, tempFileName);

To sum it all up :

protected void exportReport(CrystalDecisions.CrystalReports.Engine.ReportClass selectedReport, CrystalDecisions.Shared.ExportFormatType eft)
    selectedReport.ExportOptions.ExportFormatType = eft;

    string contentType ="";
    // Make sure asp.net has create and delete permissions in the directory
    string tempDir = System.Configuration.ConfigurationSettings.AppSettings["TempDir"];
    string tempFileName = Session.SessionID.ToString() + ".";
    switch (eft)
    case CrystalDecisions.Shared.ExportFormatType.PortableDocFormat :
        tempFileName += "pdf";
        contentType = "application/pdf";
    case CrystalDecisions.Shared.ExportFormatType.WordForWindows :
        tempFileName+= "doc";
        contentType = "application/msword";
    case CrystalDecisions.Shared.ExportFormatType.Excel :
        tempFileName+= "xls";
        contentType = "application/vnd.ms-excel";
    case CrystalDecisions.Shared.ExportFormatType.HTML32 :
    case CrystalDecisions.Shared.ExportFormatType.HTML40 :
        tempFileName+= "htm";
        contentType = "text/html";
        CrystalDecisions.Shared.HTMLFormatOptions hop = new CrystalDecisions.Shared.HTMLFormatOptions();
        hop.HTMLBaseFolderName = tempDir;
        hop.HTMLFileName = tempFileName;
        selectedReport.ExportOptions.FormatOptions = hop;

    CrystalDecisions.Shared.DiskFileDestinationOptions dfo = new CrystalDecisions.Shared.DiskFileDestinationOptions();
    dfo.DiskFileName = tempDir + tempFileName;
    selectedReport.ExportOptions.DestinationOptions = dfo;
    selectedReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;


    string tempFileNameUsed;
    if (eft == CrystalDecisions.Shared.ExportFormatType.HTML32 || eft == CrystalDecisions.Shared.ExportFormatType.HTML40)
        string[] fp = selectedReport.FilePath.Split("\\".ToCharArray());
        string leafDir = fp[fp.Length-1];
        // strip .rpt extension
        leafDir = leafDir.Substring(0, leafDir.Length – 4);
        tempFileNameUsed = string.Format("{0}{1}\\{2}", tempDir, leafDir, tempFileName);
        tempFileNameUsed = tempDir + tempFileName;

    Response.ContentType = contentType;



Which is pretty straightforward and even works. With a lot of thanks to the many people on the web who have also been strugling with this.


This entry was posted in Out+of+control. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Sourav Chakraborty

    Any idea to export only the column headers from .rpt file using Java?

  • PeterGekko

    SQL reporting services ? :)

  • Karthipriya

    i have to export the crystal report into excel format bt it has some errors while opening.whats the exact solution for export the crystal report to excel.
    plz rly me.
    –Thanks in advance

  • Sophia Jackson

    Nice tips.I found it more informative and helpful for me.Thanks for sharing.


  • alex smith

    It is exactly what I’m looking for. Btw, I found Data export component when I put similar request on Google,has anybody used this toolkit to do this job?I need some reviews about it.Thx in adv.

  • Saineshwar Bageri
  • arronlee

    But I think it needs the help of some PDF managers as well. Have you checked it out?

  • cindy313

    sorry for late comment,i’m wondering whether you guys have tried to create barcode in crystal report?

  • Prasad

    Hi Mani,
    did you find a solution of this issue.. Please post the solution for the issue. Thanks Prasad

  • http://www.facebook.com/people/Gever-Lances/100003085372152 Gever Lances
  • Pingback: Crystal 8.5 Viewer | WebDesignArticles.net | WebDesignArticles.net

  • Bruce

    I have just installed Crystal Reports 2011 and Scheduler 2008 and want to export data directly to MS excel in tab delimitted format.  Is there a way to do this other than exporting to “data only” and then opening the excel file and saving as tab delimitted?

  • Anonymous

    Sorry, can’t help you on that. I’ve moved away from CR long time ago. These post were my last attempts to try to keep it rolling…

  • Mirza Waqas Baig

    Hi, your blog is perfect to export crystal report to any format. But, the problem is that if a crystal report has some css applied, then this css doesn’t apply after being exported to any format.
    Please help me out in sorting out this problem.

  • Anupam

    I need  help in exporting a crystal rpt into different sheets in a single excel file. Different cols of a single report into different sheets. The scenario is I have 8 sets of different data, I need 2 sets in each sheet of the excel. Is this possible?

  • http://www.facebook.com/people/Michael-Juarez/100002115224464 Michael Juarez

    I have had some cpu performance issues when xporting to Excel. For some reason the latest minor patch mix solved much of the problem. I got a new computer, that probably helped too.

    Excel Reports

  • Hongclub


    Can you the solution, please email me hongclub@hotmail.com?
    After i export to PDF, i have the same issue, the link is not there.

    Please advise,

  • Mazharulsobuj

    inventory software use vb 6 database sql server 2000 and crystal report 8.5 .but my problem is report file convert to excel at os windows 2007 but at windows xp it convert easily. please help me.

  • Guest

    It’s hard to find a decent example that sets the CR’s parameters… still googling…

  • http://codebetter.com/members/Robin_2D00_Merrill/default.aspx Robin-Merrill

    I have CR Dev and am looking for a script that will supposedly enable me to schedule and post a report daily on my Intranet site for viewing and printing. I understand it needs to be written in Visual Studio or similar, and we have Visual Studio. Any guidence out there? Thanks! Robin

  • jodiet

    I have CRXI on my report, there were hyperlinks in the report which I want to export out. However, when I exported out to PDF and/or XLS, the names because the hyperlink address …
    Is there a way to present the name(s) of people – which is what the report showed – instead of the hyperlink ? Cos this is a drill-down report so the hyperlink lets them drill down further … however when exporting, it gave the hyperlink address instead of the name …

  • Mayuri

    We are having an application which is developed using Visual Studio .Net 2003 and reports are in Crystal Report 9. But when our application runs on .Net Framework 2.0, while viewing report it gives an error “The request Could not be submitted for background processing”

    Export to crystal report gets failed and it prompts above error.

    Please provide any suggesions here…..

  • dxta


    I’m using CR11.8 on Eclipse.

    I want to be able to export my reports to Excel but Excel is not listed in the dropdownlist on the Export Page.

    Is there something I need to download or configure cos I really need my reports on Excel


  • dxta


    I’m using CR11.8 on Eclipse

    I want to be able to export my report to Excel but Excel is not one of the options on the dropdownlist.

    How can I get to export to Excel? Is there something I need to download or what

    Please HELP!!!

  • harland

    I found a work around in displaying the images when exporting to html. First i created a folder ‘images’ in the folder where the aspx file is running. Then i copy the images from the temp folder to the newly created ‘images’ folder.

    in the code clean (delete all files inside) first the created ‘images’ before you copy new images, it will pile up otherwise.

    Hope it helps,

    Harland G.

  • harland

    Hi Peter,

    I am having the same problem with Greg. Export to HTML works quite well except that my report has 2 images which are not shown because of the image-path that is pointing to the aspx file folder. And since the CR created a temp folder there is no way I could set to the image-path to point to that temp folder.

  • Srivatsa

    Hello i use the same approach to export my crystal report to the pdf and other standard formats.

    The problem i am facing is ….it is taking ~4min for my report to be exported into pdf.

    The report is very bulky having ~1500 records.

    Any suggestions to improve this


  • Tenzin

    Hi all,
    I have an export issue while downloading a crystal sub-report in MS-Excel(data only and with guidelines).
    Say I have data corresponding to main report columns C1, C2 , C3 as a,b & c and data corresponding to sub report columns Sub1,Sub2 are d & e and f,g correspond to columns C6 and C7 which are again from main report .
    While exporting this to Excel, (data only format), the problem is the data for sub-report is getting displayed in the next line and the data for the columns from main report following it is getting displayed in the line after it starting from the first sub-report column

    C1 C2 C3 Sub1 Sub2 C6 C7
    a b c

    d e

    f g

    Please help

  • fraank


    we have an barcode font type. in crystal reports, the barcode is in this fonttype. if we convert it to pdf, the barcode is still in the right fonttype. but if we convert it to an editable word document, the fonttype changes to “EN”. EN are the last do charakters of the real fonttype name.

    We installed the link you’ve given ftp://ftp1.businessobjects.com/outg…net11win_en.zip
    but the problem still exist…

    can you help? greez

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen


    does the asp.net process have the necesary right to create files in the temp dir ?

  • Mohammed Aquil

    I am facing one issue related to InprocServer/TempDir in the Windows Registry.

    I have to do an implementation of one of our Intranet Solution in Canada. The application is developed using ASP.Net.

    We are using Crystal Report to create reports. You must be aware that while generating the reports Crystal Report uses C:\Windows\Temp for writing temporary files. The problem is the client does not want us to use that folder for security reasons.

    We tried entering the values in the windows registry in the InprocServer/TempDir but it throws an exception “Error in File UNKNOWN.RPT:
    The request could not be submitted for background processing.”
    Can you tell me what do I have to do inorder to handle this error.

  • DWLexus

    My report when exported, creates the CSV file with the first detail record on the group record. How do I get all of the detail records as their own records. I am using Crystal ver


  • mohit

    Got it man done that thanx for ur non usefull comments

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    That’s vague :)

    Start the usual debuging ?

    Check first which object is null, the selectedReport or the exportoptions ? Or something inside ? Check the stacktrace ?

    Etc. etc..

  • Mohit

    i have used the above code but the code is throwing an exception in the line
    selectedReport.ExportOptions.ExportFormatType = eft;
    an object reference not refer to an object, Can you give me a suggestion to avoid this exception because i have to export a file into compatible HTML32,40 format.

  • Avijit Deb Sarkar

    I can cot delete pdf file which is generated by exporting crystal repot.
    showing error file is used by another process.
    my entire code is written into .Net 2005 and the technology is ASP.Net

  • Greg

    I converted the code to vb and it works quite well. Thanks. I have ran into ont problem. We have an image on the report and when the report is exported to HTML the image is keeping the original folder location. Which would be fine, but it is looking for the temp file name that C.R. has created. Have you encountered this problem, and if so, do you have a work around?


  • guest

    I am able to export crystal report to pdf format. however, the file hyperlink in the report is not retained when its exported to pdf format. please help.

  • piyu


    I’m using CR8.5 +VB6.0

    The export button of the report page open the Export page. In the export page there is a dropdownlist with folowing formats :

    – Crystal Reports (RPT)
    – Acrobat Format (PDF)
    – Excel5.0(xsl)
    – Excel5.0(xsl)(Extended)
    – Excel7.0(xsl)
    – Excel7.0(xsl)(Extended)
    – Excel8.0(xsl)
    – Excel8.0(xsl)(Extended)
    – Word for ms
    – text
    – HTML(3.5)
    – HTML(4.0)DHTML
    – Rich Text Format

    and many more

    My question is : How to hide some of those choises ?
    (I don’t want the “- Excel5.0(xsl)(Extended)
    – Excel7.0(xsl)(Extended)
    – Excel8.0(xsl)(Extended)

    Any idea, or Plz can any one help me.

  • Nilesh

    Can anyone pls help me out….
    I used the same code as given by Peter, but I dont have excel installed on my machine. whenever I am going for the export to excel option the browser prompts me for download the .aspx page.
    Can anybody suggest me why is this happening?
    any idea
    Waiting for reply

  • muz

    can anyone help me..

    i do on crystal report 10..
    my report can export as pdf file..it work fine..but when i want to export as html it not work..got eror..

    my code as below :

    1) can export as PDF file

    Dim exportOptions As New ExportOptions()
    Dim diskOpts As New DiskFileDestinationOptions()

    ‘exportOptions.ExportFormatType = ExportFormatType.PortableDocFormat

    exportOptions.ExportDestinationType = ExportDestinationType.DiskFile

    Dim FullFileName As String = FileName
    Dim diskFileName As String
    ‘ diskFileName = AppDomain.CurrentDomain.BaseDirectory.Trim() + “Report/” + FullFileName + “.PDF”
    diskFileName =

    diskOpts.DiskFileName = diskFileName
    exportOptions.ExportDestinationOptions = diskOpts


    ‘Response.ContentType = “application/pdf”

    2) cant export as HTML…

    –> But when export as html not work n got eror ..

    Dim exportOptions As New ExportOptions()
    Dim diskOpts As New DiskFileDestinationOptions()

    exportOptions.ExportFormatType = ExportFormatType.HTML40

    exportOptions.ExportDestinationType = ExportDestinationType.DiskFile

    Dim FullFileName As String = FileName
    Dim diskFileName As String

    diskFileName = AppDomain.CurrentDomain.BaseDirectory.Trim() + “Report/” + FullFileName + “.html”

    diskOpts.DiskFileName = diskFileName
    exportOptions.ExportDestinationOptions = diskOpts


    Response.ContentType = “text/html”

    The eror will displayed :
    Object reference not set to an instance of an object.

    Line 53: diskOpts.DiskFileName = diskFileName
    Line 54: exportOptions.ExportDestinationOptions = diskOpts
    Line 55: rpt.Export(exportOptions)

    any ideas / or can anyone help me to change or add the code…
    thanks in advance

  • ashaari

    can anybody help me, i’m using crystal report in vs 2005. my database informix, i use command from crystal report for SQL. In crytal report viewer, it con view my data but if i convert to pdf. parameter missing. my parameter from session. i use this code for export :

    Dim exportFileName As String = ” ‘” & reportnum & “‘.rpt”
    Dim exportPath As String = “D:\web\WebSite8\” & reportnum & “.pdf” ‘where file will be exported
    Dim crReportDocument As New ReportDocument()
    fname = “D:\web\WebSite8\” & reportnum & “.pdf”
    Dim crExportOptions As ExportOptions
    Dim crDestOptions As New DiskFileDestinationOptions()
    crDestOptions.DiskFileName = exportPath
    crExportOptions = crReportDocument.ExportOptions
    crExportOptions.DestinationOptions = crDestOptions
    ‘Specify export destination type
    crExportOptions.ExportDestinationType = ExportDestinationType.DiskFile
    ‘Specify the format in which you want to export (like .doc,.pdf etc)
    crExportOptions.ExportFormatType = ExportFormatType.CrystalReport
    crReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, exportPath)

    Response.ContentType = “application/pdf”


    how to i want to carry parameter value. can anybody help me.

  • Hemang

    Can any one help me?

    When i Export my Report form Crystal Reports to PDF format. It works fine in windows application. But when i Export same report in Web application and display same report to user. its format is changes means it spans into more than one pages.i dont have idea about this. Please provide guidance on this.
    Thanks in Advance,

  • Ashu

    How do we quick export report in pdf,excel format with report name and report id in Business object R2.

  • Mani


    I have an application which uses the crystal viewer. All the reports are built in either Crystal 8.0 or Crystal 8.5. Within the Crystal viewer, is the option to EXPORT file to .PDF.

    This option works for me, I can export the report to a pdf and email it, however it does NOT work for any of my users. For my users, they do not get any error messages, and the file DOES get created. It’s just the file is empty, the conversion was not successful, it’s an empty file.

    I am an administrator on the server. All users log in through CITRIX and they are just users. I temporarily gave admin access to the server to one user and that user was able to Create the .pdf.

    My question is, WHAT FOLDER(S) do the users need special WRITE or change permissions, in order to use the export to pdf functionality??

    I see the export process seems to be taking place in the profile temp directory: c:\documents and settings\user_name\local settings\temp\23

    (The numbered folder is different for each user). I notice when running through the export process, several tmp files get created and once the process is complete the tmp files disappear. The users already have full control to their own profile directory.

    Also, as a test I gave full control permissions to the c:\windows\temp directory for one user. That didn’t make a difference either.

    What else could it be??? I can’t make all the users admins on the server.



  • Priya

    I want to format Report when i am formatting report in HTML3.0 using ExporttoDisk method.
    Report is in proper format when i am exporting in pdf format but in html its alignment r getting disturbed.
    I will appreciate any type of help……

  • Nah

    I really will appreciate ant help

    I’m using CR10 + ASP.NET.
    The export button of the report page open the Export page. In the export page there is a dropdownlist with folowing formats :
    – Crystal Reports (RPT)
    – Acrobat Format (PDF)
    – MS Word
    – MS Excel 97-2000
    – MS Excel 97-2000 (data only)
    – Rich Text Format

    My question is : How to hide some of those choises ? (I don’t want the “Crystal Reports (RPT)” MS Word
    – MS Excel 97-2000
    export format in the list)

  • Mahesh

    i used the same way of creating reports. but i am facing a weird problem.. the reports are working on one machine ( test server) but on the live machine the reports are coming blank… i tried to catch some exception if they are arising but no exceptions are raised but still the report is coming blank…

    plz plz help me on this…

    thanx in advance

  • Sanjay


    We recently upgraded from 8.5 CR to BOE Xi R2 version. After the upgrade/migrate, all the reports have layout problems. We export the data for all our reports into Excel. In 8.5 version, the grid lines were visible and there were no white background. However, in CRXi/BOEXi version, we see that there are no grid lines and a white background appears. Its almost like seeing a word document in Excel.

    Is there any solution for this? How to overcome this white background and be able to see the grid lines? Any help is highly appreciated.


  • invincible

    Do we have a similar workaround like the one posted by Peter for Java. I am using JRC for Crystal Reports Developer XI Release 1. Does anyone have any idea how to export a report to an excel format??

  • Jportelas

    When I try to export to PDF after a previous exporting operation to word doc and error arises telling me that some unknown characteres where found. (VSNET 2003 .NET 1.1).
    Any hints on this?

  • syam

    can u tell me a solution for this

  • syam

    can we export cr9 to word without textboxes and should not lose data in textboxes

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    This code has only been tested and used under 1.1. I don’t know anything about the combination of CR an 2.0 as I dropped Crystal in favor of SQL reporting services.

  • Bob G.

    Have you tried this method with .NET 2.0? The FilePath is not an attribute of the Crystal Reports ReportClass associated with this version of .NET. How can I get that attribute? Any ideas? Thanks.

  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    Thanks for sharing :)

  • http://naresh_bojja@yahoo.com Naresh Bojja

    Hi all,
    i got an error while exporting crystal report to pdf file(Error detected by export.dll error is c:/temp/……..rpt) file. i got the slution to this.
    the solution for this is, u have to install a new servicepack which is available at

    after installing this servicepack just restart ur system, ur application wil works fine without changing any font or anything else.

    this is the link for the new merge modules


    thank u,
    Naresh Bojja.

  • Carlton

    This works! I ran into a small issue between IE and Firefox where FF allowed “Application/pdf”, but IE wanted “application/pdf”. Never thought I would find windows to be case sensitive, but I figured it out with your example. Thanks.

  • http://codebetter.com/blogs/peter.van.ooijen/default.aspx pvanooijen

    Most likely it’s a security issue. The asp.net account needs the right to write to the temp directory. By default it does not have any write rights.

  • Mike4QL

    There is a lot of useful stuff in here which has helped a lot in coding PDF exports from ASP.net (1.1).

    However, I am left with one problem that I cannot find a solution to.

    I have a report embedded in a web application. I use .Export and .Close to create a PDF file which I then download to the user.

    This works perfectly on my development machine (XP running vs.net 2003) but when I install it on 2 different W2k based servers CR fails to create the export file. There are no error messages. Everything appears to work but the export file never appears.

    Any ideas what might cause that?


  • http://codebetter.com/blogs/peter.van.ooijen/ pvanooijen

    I’m sorry but CR is a closed chapter for me as I’ve switched to SQL reporting services. (Which also has nasty quircks).
    But I don’t know any more about CR than written here.

  • Alberto

    I´m using Crystal Reports to generate some Invitations un MSWORD format (.doc).
    I have done the report and in the preview everything seems ok, but when i Exported it to MSword the generated archive has not the same format. Surprisingly it only happen when i exported it to word, with PDf everything goes well.

    I would be very gratefull if you could help me. You can write me to amdiez@indra.es

    Thanks and Regards.

  • supz


    I am using the same method as above to export my Crsytal Report to PDF file.

    This was working until yesterday. All of a sudden I get an error on running the page saying “Cannot find file”. This refers to the PDF file I’m trying to export to. I do not get any exception on the rport.Export() statement.

    I’ve checked all permissions on this folder, the ASPNET user has full control of this file folder. What could be wrong??

    Also would like to know the correct method of passing parameters to the report when exporting to PDF.

    Any help would be appreciated.


  • Vishal


    Does anyone know how to control version of exported PDF file(s) from CE10. By default, export to pdf generates files in Acrobat 6.0 (or higher) format. Is there any way to specify that the conversion should generate files in Acrobat 5 format?



  • http://codebetter.com/blogs/peter.van.ooijen/ Peter van Ooijen

    I do not think that is possible. Given the hoops you need to get it done for a plain file.

  • Arockiam

    I a using ExportToStream Method

    This will work fine for pdf/word/rtf/xls

    but failed in HTML32/HTML40

    Dim st As System.IO.MemoryStream

    st = rptDcmt.ExportToStream(CrystalDecisions.[Shared].ExportFormatType.HTML32)

    Dim b(st.Length) As Byte

    st.Read(b, 0, st.Length)

    With HttpContext.Current.Response



    .ContentType = "text/html"




    End With

    The error follows:

    Could not find file "C:\DOCUME~1……..\temp\***.tmp"

    i want to don’t write as file.

    pls help to me.

    Thanks in advance.

  • http://codebetter.com/blogs/peter.van.ooijen/ Peter van Ooijen

    If you want full control of Word or Excel I would go for automation.

  • Igor

    I will try to answer 2 of the questions above

    1) in CR10 constant for HTML format is 7

    2) to use stream rather than making a trip to Hard Drive each time do this:

    Dim retval As Byte() = New Byte() {}

    Dim s As System.IO.MemoryStream

    s = m_Report.ExportToStream _(ExportFormatType.PortableDocFormat)

    retval = s.ToArray


    With HttpContext.Current.Response



    .ContentType = "application/pdf"

    .AddHeader("Content-Disposition", "inline; filename=DailyReport.pdf")



    End With

    with tweaking you can get all formats to open directly in browser without cluttering server

    unfortunately none of my advanced reports translates to excel or word with enough precision

    if there is a way to influence this issue please let me know

  • NoCR4Me

    I am using CR 10. I don’t have any problems exporting in PDF and RTF formats, but when I try to export in HTML, it gives a com error -2147190908 (dll missing). I have added/registered ALL (according to CR documnet) dlls. Please help me.

  • Peter van Ooijen

    you’re welcome. Thank you !

    imho nothing beats PDF for nice and usable reporting in a browser. The Excel version is Ok for custom analysis. The Word version sits somewhere in the middle.

  • Aidas Stalmokas


    It’s WORKING!!!!

    At first I spend tons of time to getting crystalReports to work in CR format (finaly did thanks to report of Ajay in http://aspalliance.com/articleViewer.aspx?aId=265&pId=2) but CR in web printing did not satisfied me (even zooming and page’ing didn’t work).

    And here I found your article. It’s GREAT!!!

  • Ole Wielund

    I haven’t tried it yet, but it will be my next move.

  • Peter van Ooijen

    No I don’t… Can you reproduce that on another machine ??

  • Ole Wielund


    I am using the above code to export in the format of pdf, doc, xls.

    The code end’s with the delete of the file. This works well for doc and xls, both pdf only works if I don’t delete the file.

    Do you have any ideas?


  • Export to CSV Format and MPP Format in Crystal Rep

    How to Export to CSV Format and MPP Format in Crystal Reports

  • Peter van Ooijen


    thank you ever so much for your help turning this blog into a wiki http://dotnetjunkies.com/WebLog/petergekko/archive/2004/04/26/12183.aspx

  • Sri

    // Adds each parameter

    private void AddParamFieldDefinition(ParameterFieldDefinitions parameterFieldDefinitions, string paramName, object paramValue)


    prmValues prmValues;

    ParameterDiscreteValue parameterDiscreteValue = new ParameterDiscreteValue();

    parameterDiscreteValue.Value = paramValue;

    prmValues = parameterFieldDefinitions[paramName].CurrentValues;




    // Calls the previous method for one parameter

    private void AddParamFieldDefinition(ref ReportDocument CrystalReport, string paramName, object paramValue)


    AddParamFieldDefinition(CrystalReport.DataDefinition.ParameterFields, paramName, paramValue);


    Iterate through each parameter value that is available to u and call the second function in the second loop

    Hpe this helps

  • Karizma

    Even i face the same problem with the export.

    how do i assign the parameters to Reportdocument ?

  • Sachin

    How do i export a report with parameters ? how do i specify the parameters to the report document plzz help

    When i export the report is gives me an error mentioning "Missing Parameter field current value"

    Please Help

    thanks in Advance

  • Sachin

    How do i export a report with parameters ? how do i specify the parameters to the report document plzz help

  • Dana Hurtig

    When exporting to excel or rtf, the file save prompts with the wrong extension (.aspx) for the file. Export to PDF and Word works great. If I manually change the extension before saving, it works. Any ideas?

  • Peter van Ooijen

    I’m sorry but don’t look at this post, it is about CR for asp.net 1.1. Which is different from CR for ASP.NET 1.0. And far different from CR for VB Windows.

    One of the main problem with CR is that it is changing with every version. Will keep you busy forever :)

  • Deepasree

    Hi All,

    I am using crystal reports 5.0 with VB6 . When I export Crystal reports in HTML format , asking me to select a path for the html file .The changed path is affecting the application path i.e it is chnaging the CURDIR$ of my application itself to the selected path. Any suggestions to resolve this issue ? Please help.

  • Peter van 0oijen

    I don’t know. My story is based on ASP.NET. In your case I would expect it to be somewhere in the official temp dir of Windows. Can’t you trace the file based on the other info ?

  • Mark Bain

    I am running my export in a service, therefore I have no Session.SessionID… what is the name of the temp file?



  • Peter van 0oijen

    You talk to CR10 via COM, I use the VS.NET wrappers.

    You use hard coded values to set the type, I use the .NET enumeration


    Members :









    There is overlap but the sequence differs.

    I don’t think you can map my story to your scenario. What I would do is give it a blind try, just throw some values at CR and see what comes back. Or find the documentation of the crExportControl…

  • Shams

    This is the code I used in CSP page and it works for PDF

    Dim expOpt

    Dim formatOpt

    Dim exportControl

    Set ObjFactory=Server.createobject ("Crystalreports.objectfactory")

    ‘Create the Export Options Object

    Set expOpt = objFactory.CreateObject("CrystalReports.ExportOptions")

    ‘Create the Format Options Object

    Set formatOpt = objFactory.CreateObject("CrystalReports.PDFExportFormatOptions")

    ‘Export Format Constants


    ‘Crystal Report = 0

    ‘MS Word = 1

    ‘MS Excel = 2

    ‘RTF = 3

    ‘Excel(Data Only) = 6

    ‘Text = 7

    ‘Character Separated Values = 8

    ‘Set format options for export

    expOpt.FormatOptions = formatOpt

    ‘Define export format

    crReportExportFormatPDF = 5

    ‘Set Format Type

    expOpt.ExportFormatType = crReportExportFormatPDF

    ‘Create a Crystal Report Export Control.

    Set exportControl = Server.CreateObject("CrystalReports.CrystalReportExportControl")

    So by this way the report will open as a PDF but now I need to modify this code to open it as HTML.

    SO what do you think? Any advice

  • Peter van 0oijen

    Sorry about that. This post is on the CR 9 as it is in the vs box. I only know the differences between the versions are quite structural.

    Why are you using hard coded nummerical constants and not the CrystalDecisions.Shared.ExportFormatType enumeration ? Or whatever name that has in CR 10.

  • Shams


    Hi, I really will appreciate any respond for this issue:

    I’m using CR10 + CSP page and ASP.NET.Application

    I got Export to PDF format working fine by using Export Format Constants value in CSP page.

    crReportExportFormatPDF = 5

    But my problem now I can’t find what is the

    Export Format Constants for HTML.


    ‘Crystal Report = 0

    ‘MS Word = 1

    ‘MS Excel = 2

    ‘RTF = 3

    ‘Excel(Data Only) = 6

    ‘Text = 7

    ‘Character Separated Values = 8


  • jjp

    how about mulit rpt to pdf

    like report1.rpt, report2.rpt to pdf1.pdf

    can I do that?

  • Albert

    There is any way to export to Word or Excel in a read only document (no editable)???

  • Habib

    I have a graph report when I export it to Excel its exporting well but the lines in lagend are not exporting to excel.Any one canm help in it?

  • NHM

    ok, ok , i got it… easy… just keep the fields (on the designer) tight together… don’t leave any spaces between them… and excel will eat it just right…

  • NHM

    Hi, after u export to Excel… the columns are nicely created, but it creates empty columns between each of the data columns, which difficults the sorting…

    any ideas to prevent the creation of this empty columns?


    Nuno Mendes

  • Aruna

    Hotfix from crystal reports


    fixed the error "Error in DLL" while exporting to PDF.

    Thanks everyone for inputs.


  • Peter van Ooijen

    That’s default behaviour of (the) Word viewer in IE. If you want to change that from your web server for your user’s browser you could try to do it using automation in the script of the browser… Slippy territory.

  • nalin

    when i use application/msword, the required page opens in the explorer window but without word’s standard & formating toolbar (for this i have to manually active the said toolbars).

    any addition in the script i can do to pre-activate the menus so that users dont have to do the same

  • Aruna

    Thanks for your input again. So far I found out that machines that has Adobe 6.0 Standard installed works fine. Ones with Adobe 6.0 Professional installed does not work. Gives the same error. Unfortunately, uninstalling 6.0 Professional and re-installing 6.0 Standard did not help either.

  • Peter van Ooijen

    You get the error because Crystal has not closed the file yet. It’s still using it. If the problem is only there with the pdf output I would check Adobe. Perhaps the Pro version doesn’t like your app competing ? And yes, DLL’s not being registered properly will give problems.

    The are all the open doors I can kick in..

  • Aruna

    Thanks for your response. With regard to your suggestion, the file it creates goes to c:\documents and settings\local settings\user\temp\temp file name.rpt (where all directory names over 8 letters are shortened with a ~1. While it is giving the error message I went to document and setting directory and checked that a .RPT temp file of 2k bytes exists and till I close my application it does not let me open the file saying somebody is already accessing it. So, I am thinking it may not be access problem since the temp file is created. Do you have any other ideas.

    Imp Note: The same application works in another machine i have. It has the same operating system and old one has VS.Net std and new one with the problem has vs.net architect version (with Visio, VSS) etc. Old one has Adobe 6.0 std and new one has Adobe 6.0 Prof. ALso, exporting to XLS works fine in both (Both in XLS and PDF option I point to the same directory on network).

    I tend to think this could be a problem with some DLLs not being registered okay.

    Let me know if you have ideas or further questions. (hope i have not confused).

  • Peter van Ooijen

    These formats come with the default install of CR. I think the error in file points to an non existent directory or the lack of rights to write to the directory. Crystals error messages are often very misleading.

  • Peter van Ooijen

    I suggest you write the HTML mail message to a temporary file and send that file to mail. You’ll have to look in the MSmail docs what kind of inputs it accepts as a message body.

  • Alex

    Does ANYONE know how to export report into HTML with destination being MicrosoftMail instead DiskFile? I get "The directory is empty" error message if I try to export to HTML with destination set to Microsoft Mail.

    I specify both HTMLBaseFolderName and HTMLFileName, but I still get the error…


  • Aruna

    Have any of you received error while exporting to PDF (from vb.net appln). CrystalDecisions.CrystalReports.Engine.ExportException: Error in file .. Error detected by export DLL? Is there any specific downloads to be installed for exporting CR to PDF. Let me know if you need further information.

    Thanks, Aruna.

  • Pad

    Good One

  • Sbr


    I’m using CR10 + ASP.NET.

    The export button of the report page open the Export page. In the export page there is a dropdownlist with folowing formats :

    – Crystal Reports (RPT)

    – Acrobat Format (PDF)

    – MS Word

    – MS Excel 97-2000

    – MS Excel 97-2000 (data only)

    – Rich Text Format

    My question is : How to hide some of those choises ? (I don’t want the "Crystal Reports (RPT)" export format in the list)

  • jaiganesh

    i am not able to exporting from crystal reports to wordm, could you find out and tell me,(exporting is working but the format is not come)

  • Fan

    Thanks, working great

  • Peter van Ooijen

    The error is on a temp report file. Does you app have the rights to scratch in that dir ? afaik this error message pops up when it does not.

    I have a another Crystal post on this http://dotnetjunkies.com/WebLog/petergekko/archive/2004/01/16/5678.aspx

  • Got an Error (2) code

    protected CrystalDecisions.Web.CrystalReportViewer CrystalReportViewer1;

    Utility ou = new Utility();

    protected System.Web.UI.WebControls.Button btnPrint;

    protected RPT_ChargebackByPaymentType rcpt;

    private void Page_Load(object sender, System.EventArgs e)


    rcpt = new RPT_ChargebackByPaymentType();


    CrystalReportViewer1.ReportSource = rcpt;

    CrystalReportViewer1.Visible = true;


    private void btnPrint_Click(object sender, System.EventArgs e)




  • FAN

    Error in File C:\DOCUME~1\PGSREP~1\ASPNET\LOCALS~1\Temp\temp_25c38772-b7c2-41b1-a4a4-095fa7f44ede.rpt: Access to report file denied. Another program may be using it.

  • Peter van Ooijen

    I wouldn’t use Crystal to do this but talk to Excel directly using automation.

  • shruthi

    my problem is to export 1500 pages of reports to excel sheet. when i try to hit the export button , excel sheet comes but without any data . is this bcoz of the size? if this is,then how to handle large amount of reports for exporting

  • Brett

    Is there a way to export specific fields from the Crystal Report to an Excel file instead of exporting the entire Crystal Report????

  • Peter van Ooijen

    Error message ? Containing what ? Wrong directory ? No rights to create temp file ?

  • Jimmy

    I try to use ExportToDisk to export the HTML file, but the system error message. Any idea on the problem?

  • Jimmy

    I try to convert the c# code to vb.net, pdf and doc format is working fine, however I encounter the problem in exporting the html file from the report. is there any different between c# and vb.net code in exporting the html file from the report

  • Peter van Ooijen

    I’ll dive into the parameters problem when the need arises :> And blog about all solutions / problems found.

  • Brent Railey

    When I try to execute an export, it seems to not be passing the parameters to the report.

    I set them in code, but when I view the export, it always has just the default values of the parameters.

  • Peter van Ooijen

    I’m not sure if I understand the question.

    In the post is a method which takes a report as a parameter. Before sending your report to the method you can do anything with the report you would like to do.

  • vijay

    what in case id one parameter set in crystal report take more then one values how do u send parameter to report and get output exported

  • Peter van Ooijen

    Afaik these are all the formats CR supports.

    When it comes to csv I would do that by hand or use something like DTS (sql server).

  • Pradeep

    Hey Pete,

    Is there a way I could export the .RPT file to a .CSV file?

    Pls advise

  • Peter van Ooijen

    That is a setting of the PDF viewer, not the document itself. Maybe you can do that using some script in which you address the viewer as an ActiveX control.

  • Divebouy

    Sorry, using CR9, ASP.NET framework.

  • Divebouy

    Any way to remove the toolbars from the exported PDF? I want to ensure that my users can’t edit the PDF. Currently streaming to browser but haven’t figured this one out.


  • Peter

    Thanks !

  • Wajid

    ReportDocument doc = new ReportDocument ();



    ExportOptions exportOpts = doc.ExportOptions;

    exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;

    exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;

    exportOpts.DestinationOptions = new DiskFileDestinationOptions();

    string Fname ="C:\\T\\" + Session.SessionID + ".pdf";

    DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();

    ( ( DiskFileDestinationOptions )doc.ExportOptions.DestinationOptions ).DiskFileName = Fname ; //Server.MapPath("fin.pdf");




    Response.ContentType = "application/pdf";

    //Response.ContentType = "application/msword";




  • Dave

    Has anyone had any luck exporting CR to streams? I can use crReport.ExportToStream(format) fine for the format types CrystalReport and PDF, but everytime I try using it for HTML (3.2 or 4.0), it blows up with a FileNotFoundException (it’s looking in the DocumentsAndSettings\username\LocalSettings\Temp folder for a temp_*******.tmp file. The ******* looks like a guid, but it’s different from the one identified above.

    As a sanity check, I’m not even running in ASP.Net yet; I’m using WinForms to do my feasibility testing, and I’m an admin on the machine.


  • Peter van Ooijen

    That’s an Excel setting which is not in the CR enumeration of options. You can access Excel using COM, but I’m not sure about the Excel viewer. What you could try is inject a little script which will set the option.

  • eaz

    I do stuff similiar to export to an excel file, but when I do, I see no grid lines in the created excel file by default. Is there a way to set this so that it shows the grid lines? (It looks like a word document running somehow inside excel…)



  • Peter van Ooijen

    Afaik the CR which ships with VS only supports the four formats described here. In case anybody knows of another format, I’ll gladly incorporate it in the example.

  • Ramesh


    Is there any way to export .rpt files as text files. I am using crystal reports 9.0 and .Net framework..

    I want to export them dynamically in the code.

    I could able to export to pdf,doc and html..But not to text.