How to export Crystal Report in PDF, HTML and DOC formats using C # code in ASP.NET?

I developed a report on my ASP.NET website, now I need to provide options for exporting this report to PDF, HTML, and DOC formats, how can I achieve this?

The Crystal report has one button for this, but when I ever try to save this report, it is saved as .aspx format as I view it on the asp.net web page.

+5
source share
3 answers

You need to do this yourself: create a drop-down list with the required formats and a button to make a postback for export.

.Net 1.1/CR9. :

  • MyReport.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
  • .pdf, : MyReport.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat; WordForWindows, RichText, Excel, HTML40 ..
  • :

    CrystalDecisions.Shared.DiskFileDestinationOptions fileOptions = new DiskFileDestinationOptions();

    fileOptions.DiskFileName = "someTmpFileName";

    MyReport.DestinationOptions = fileOptions;

    MyReport.Export();

ExportOptions .

VS 2005/.Net 2

+1

:

  <asp:ImageButton Width="20px" Height="20px" ID="btnPdf" runat="server"
    OnClick="btnExport_Click" ImageUrl="~/Images/PDF.png" AlternateText="Export To PDF" CssClass="AddedButton" />
   <asp:ImageButton Width="20px" Height="20px" ID="btnXls" runat="server" 
    OnClick="btnExport_Click" ImageUrl="~/Images/XLS.png" AlternateText="Export To Excel" />   
   <asp:ImageButton Width="20px" Height="20px" ID="btnDoc" runat="server" 
    OnClick="btnExport_Click" ImageUrl="~/Images/DOC.png" AlternateText="Export To Word" />   

#:

protected void btnExport_Click(object sender, EventArgs e)
{
    // Stop buffering the response
    Response.Buffer = false;
    // Clear the response content and headers
    Response.ClearContent();
    Response.ClearHeaders();
    try
    {
        string senderID = ((ImageButton)sender).ID;
        if (senderID == "btnPdf")
            reportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, Page.Title);
        else if (senderID == "btnXls")
            reportDocument.ExportToHttpResponse(ExportFormatType.ExcelRecord, Response, true, Page.Title);
        else if (senderID == "btnDoc")
            reportDocument.ExportToHttpResponse(ExportFormatType.WordForWindows, Response, true, Page.Title);
        // There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
    }
    catch (Exception ex)
    {
       //error management

    }
}
+2

Crystal, Word, excel, odf ..

Crystal

0

All Articles