如何使用c#将rdlc报告保存在文件夹中

时间:2014-09-18 10:03:59

标签: c# asp.net rdlc

我在这个主题上做了很多搜索,但我没有得到任何正确的解决方案。  我想自动将rdlc报告保存在文件夹中。

3 个答案:

答案 0 :(得分:1)

目前您无法保存rdlc报告。但您可以将其导出为其他格式并保存(Word / Excel / Pdf)。因为rdlc文件由报告查看器呈现。

答案 1 :(得分:0)

private void savereport( )
    { string FileName = "File_" + DateTime.Now.ToString("ddMMyyyyhhmmss") +".pdf";
            string extension;
            string encoding;
            string mimeType;
            string[] streams;
            Warning[] warnings;

            string contentType = "application/pdf";

            Byte[] mybytes = ReportViewer1.LocalReport.Render("PDF", null,
                            out extension, out encoding,
                            out mimeType, out streams, out warnings); //for exporting to PDF  
            using (FileStream fs = File.Create(Server.MapPath("~/Report/") + FileName))
            {
                fs.Write(mybytes, 0, mybytes.Length);
            }

            //Response.ClearHeaders();
            //Response.ClearContent();
            //Response.Buffer = true;
            //Response.Clear();
            Response.ContentType = contentType;
            Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName);
            Response.WriteFile(Server.MapPath("~/Report/" + FileName));
            Response.Flush();
            //Response.Close();
            //Response.End();   
    }

答案 2 :(得分:0)

ModelRealEstate.DB_RealEstateEntities objdb = new ModelRealEstate.DB_RealEstateEntities();

        var rows = objdb.Tbl_Property.Where(x => x.Adress.Contains(mtxbxRprt.Text)).ToList();
        reportViewer1.LocalReport.ReportPath = ("Report1.rdlc");
        reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter("P2", mtxbxRprt.Text));

        reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", rows));

        reportViewer1.RefreshReport();