使用Asp.net中的Response打印rdlc报告

时间:2014-03-06 05:04:32

标签: asp.net

    byte[] bytes = null;
string strDeviceInfo = "";
string strMimeType = "";
string strEncoding = "";
string strExtension = "";
string[] strStreams = null;
Warning[] warnings = null;

try
{
    ReportDataSource rds = new ReportDataSource("f_MANPOWERREQUISITION");
    ReportViewer rptViewer1 = new ReportViewer();
    rptViewer1.ProcessingMode = ProcessingMode.Local;
    rptViewer1.LocalReport.ReportPath = Server.MapPath("Report.rdlc");
    bytes = rptViewer1.LocalReport.Render(strFormat, strDeviceInfo, out strMimeType, out  strEncoding, out strExtension, out strStreams, out warnings);
    Response.Buffer = true;
    Response.Clear();
    Response.ContentType = strMimeType;
    Response.AddHeader("content-disposition", "attachment; filename=" + strNomFichier + "." + strFormat);
    Response.BinaryWrite(bytes); // create the file
    Response.Flush();
}// send it to the client to download
catch (Exception ex)
{
}

此代码用于下载pdf文件..但我想打印文件,以便输出文件打开浏览器的打印预览。  所以任何人都可以帮助在浏览器中打印pdf文件....谢谢......

1 个答案:

答案 0 :(得分:0)

感谢您发布此代码。我只是将其复制并粘贴到我的应用程序中,以成功将pdf下载到浏览器中。您的问题很容易修复。改变附件;内联;在Response.AddHeader行。