如何在IE和Opera中将RDLC渲染为PDF

时间:2013-05-20 02:58:24

标签: c# asp.net internet-explorer pdf rdlc

我的问题似乎是一个重复的问题,但我在这里有一个奇怪的问题。我们有一个Web应用程序,它将RDLC报告呈现为PDF格式,其中有一些参数将在代码中设置,然后附加到报告并将其呈现为PDF。 我有这个代码:

LocalReport rep = new LocalReport();
        rep.ReportPath = "ReimbursementClaimForm.rdlc";
        List<ReportParameter> param = new List<ReportParameter>();
        param.Add(new ReportParameter("NameofthePatient", txtNameofthePatient.Text));
        param.Add(new ReportParameter("MBASIDNo", txtMBASIDNo.Text));
        param.Add(new ReportParameter("DateofBirth", string.Format("{0:dd MMMM, yyyy}", Convert.ToDateTime(txtDateofBirth.Text))));
        param.Add(new ReportParameter("CompleteHomeAddress", txtCompleteHomeAddress.Text));
        param.Add(new ReportParameter("EmailAddress", txtEmailAddress.Text));
        param.Add(new ReportParameter("ContactNos", txtContactNos.Text));
        param.Add(new ReportParameter("ExpenseClaim", txtExpenseClaim.Text));
        param.Add(new ReportParameter("AccountHolderName", txtAccountHolderName.Text));
        param.Add(new ReportParameter("AccountHolderName2", txtAccountHolderName2.Text));
        param.Add(new ReportParameter("AccountNoandAccountType", txtAccountNoandAccountType.Text));
        param.Add(new ReportParameter("BankName", txtBankName.Text));
        param.Add(new ReportParameter("BankBranch", txtBankBranch.Text));
        param.Add(new ReportParameter("BankContactNo", txtBankContactNo.Text));
        param.Add(new ReportParameter("BankAddress", txtBankAddress.Text));
        param.Add(new ReportParameter("BICSwiftCode", txtBICSwiftCode.Text));
        param.Add(new ReportParameter("RTGSCode", txtRTGSCode.Text));
        param.Add(new ReportParameter("IBAN", txtIBAN.Text));
rep.SetParameters(param);
        rep.DisplayName = "ReimbursementClaimForm";
        rep.Refresh();
HttpContext.Current.Response.Buffer = true;
        //HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.AppendHeader("content-disposition", "attachement filename=" + Rep.DisplayName + ".pdf");
        HttpContext.Current.Response.ContentType = "application/PDF";
Warning[] warnings;
            string[] streamids;
            string mimeType;
            string encoding;
            string extension;
            byte[] bytes = item.Render("Pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);
        HttpContext.Current.Response.BinaryWrite(bytes);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();

这里的问题是,每当我使用此代码部署应用程序时,ReportParameter上根据ASP上的文本框值设置的值不会反映在生成的PDF文件中。首先尝试渲染的值,但第二次尝试在PDF上未更新的值。这种情况发生在IE浏览器和Opera浏览器上,但在其他浏览器上它很好并且注意一旦Web应用程序部署在IIS上,但在我的本地机器上它在所有浏览器中都能正常工作。提前谢谢。

1 个答案:

答案 0 :(得分:0)

最有可能是缓存问题。 将此行添加到Response.Clear()

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);

清除浏览器缓存,然后重试