将水晶报告转换为pdf格式

时间:2013-04-25 09:15:11

标签: c#

我的报告在IIS中成功生成,现在我希望以PDF格式获取该报告。请指导我 - 我在下面列出了我的来源:

 protected void Button1_Click(object sender, EventArgs e)
{
    ReportDocument rpt = new ReportDocument();
    rpt.Load(Server.MapPath("MR.rpt"));
    rpt.SetDatabaseLogon("", "", "RAMYA-BD", "");
    rpt.SetParameterValue("MRNO", ddlmrno.SelectedItem.Text);

    CrystalReportViewer1.ReportSource = rpt;
    Response.ContentType = "application/pdf";
}

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

如果您没有添加查看器:

Stream st = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition", "attachment;filename=\"xxx.pdf\"");
st.CopyStream(Response.OutputStream);
Response.Output.Flush();
Response.End();

数据库连接可能

rep.DataSourceConnections[0].SetLogon("Login","Password");