从水晶报告导出PDF

时间:2015-06-25 17:43:54

标签: c# pdf crystal-reports export-to-pdf

我正在为用户输入的特定Invoice No生成水晶报告。 Crystal报表第一次在exported PDF成功SampleInvoice.pdf但是当我同时生成另一个Crystal报表时,新报表未获得ExportedSampleInvoice.pdf保持不变。

这是我生成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();

这就是我导出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();
     }

有没有办法在我生成另一张PDF后立即清除它?

0 个答案:

没有答案
相关问题