2013-04-25 103 views
0

我的報告在IIS中成功生成,現在我想以PDF格式獲取該報告。請指導我 - 我下面列出我的源:將水晶報告轉換爲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"; 
} 

回答

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"); 
+0

如果我把這個代碼意味着它無法連接顯示像錯誤:不正確登錄參數。 Stream st = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); – vivek 2013-04-25 09:29:26

+0

我給了所有在適當的甲酸鹽,但它顯示錯誤 – vivek 2013-04-25 09:38:51

+0

你沒有第一次刪除所有行。問題出在正確的一組參數上。第一行是做轉換。如果您不做此轉換,則不能導出。我不使用SetDatabaseLogon。 – 2013-04-25 09:41:50