Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在asp.net中保存转换为pdf的crystal报表_Asp.net - Fatal编程技术网

如何在asp.net中保存转换为pdf的crystal报表

如何在asp.net中保存转换为pdf的crystal报表,asp.net,Asp.net,我编写了将crystal报表转换为pdf的代码,但它无法将pdf文件自动存储到我的项目中 protected void Page_Load(object sender, EventArgs e) { CrystalReportViewer1.ReportSource = getReportDocument(); CrystalReportViewer1.DataBind(); // Get the report document ReportDocument re

我编写了将crystal报表转换为pdf的代码,但它无法将pdf文件自动存储到我的项目中

protected void Page_Load(object sender, EventArgs e)
{
    CrystalReportViewer1.ReportSource = getReportDocument();
    CrystalReportViewer1.DataBind();
    // Get the report document
    ReportDocument repDoc = getReportDocument();
    // Stop buffering the response
    Response.Buffer = false;
    // Clear the response content and headers
    Response.ClearContent();
    Response.ClearHeaders();
    try
    {
        // Export the Report to Response stream in PDF format and file name Customers
        repDoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "TFA");

        // There are other format options available such as Word, Excel, CVS, and HTML in the ExportFormatType Enum given by crystal reports
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
        ex = null;
    }
}

private ReportDocument getReportDocument()
{
  // File Path for Crystal Report
  string repFilePath = Server.MapPath("~/CrystalReport1.rpt");
  // Declare a new Crystal Report Document object
  // and the report file into the report document
  ReportDocument repDoc = new ReportDocument();

  repDoc.Load(repFilePath);

  // Set the datasource by getting the dataset from business
  // layer and
 // In our case business layer is getCustomerData function
 return repDoc;
}

在我参与的一个老项目中,我在一个新的浏览器窗口中打开了pdf报告,因此,用户可以选择是否保存该文件。

您的意思是生成的PDF文件不会在项目文件中创建索引?我想将PDF文件存储在某个位置或发送到邮件。如果解决了您的问题,请标记答案。:)但在我的项目中,it存储PDF报告自动不起作用。你能告诉我在哪里替换这个代码吗?以前的代码将它放在表单加载中,并用if(!page.ispostback())覆盖它,但它不能刷新。当我们向它添加任何值时,它不会反映到crystal报告中。。
 ExportOptions objExOpt;
            CrystalReportViewer1.ReportSource = (object)getReportDocument();
            CrystalReportViewer1.DataBind();
            // Get the report document
            ReportDocument repDoc = getReportDocument();
            repDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
            repDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
            DiskFileDestinationOptions objDiskOpt = new DiskFileDestinationOptions();
            objDiskOpt.DiskFileName = @"c:\r.pdf";
            repDoc.ExportOptions.DestinationOptions = objDiskOpt;
            repDoc.Export();