Export PDF from crystal Report

1.2k views Asked by At

I am generating crystal reports on a particular Invoice No entered by user. The Crystal Report is successfully exported as PDF in SampleInvoice.pdf for the first time but when I generate another Crystal report at the same time, the new one doesn't get Exported and SampleInvoice.pdf remains same.

This is how I generate Crystal Report

        SqlConnection con = new SqlConnection("Data source=.;Initial catalog=InvoiceSystem;user id =sa;password=rfm");
        con.Open();
       // string query = "Select * from tblInvoice";
        SqlDataAdapter da = new SqlDataAdapter("sp_Report", con);
        da.SelectCommand.CommandType = CommandType.StoredProcedure;
        da.SelectCommand.Parameters.Add("@InvoiceNo", SqlDbType.Int).Value = txtInvoice.Text;
        con.Close();
        InvoiceDataSet DS = new InvoiceDataSet();
        da.Fill(DS, "tblInvoice");
        con.Close();
        rpt.Load(Server.MapPath("~/CrystalReport3.rpt"));
        rpt.SetDataSource(DS);
        CrystalReportViewer1.ReportSource = rpt;
        ExportPDf();

This is how I am exporting PDF

        string filepath = "E:\\SampleInvoice.pdf";
        public void ExportPDf()
        {
           ExportOptions CrExportOptions;
           DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
           PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
           CrDiskFileDestinationOptions.DiskFileName = filepath;
           CrExportOptions = rpt.ExportOptions;//Report document  object has to be given here
           CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
           CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
           CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
           CrExportOptions.FormatOptions = CrFormatTypeOptions;
           rpt.Export();
     }

Is there any way I can clear my PDF as soon as I generate another one?

0

There are 0 answers