2012-02-14 118 views
5

對於我讀過,的ReportViewer打印按鈕不會在谷歌Chrome和Firefox,因爲它使用ActiveX控件只在IE工作作了。所以我試圖在報告之外製作一個asp.net按鈕並以編程方式打印報告,但這很痛苦,我想知道是否有一個更簡單的解決方法來讓報告在Google Chrome中打印。的ReportViewer打印按鈕

編輯/更新:我發現這是應該的Firefox和谷歌Chrome這個工作的ReportViewer打印按鈕,它似乎是工作的Firefox,但它打印了我一個空白頁,谷歌瀏覽器。 http://cafalse.blogspot.com/2011/04/reportviewer-print-button-for-firefox.html

回答

1

如果您不介意在頁面上某處添加您自己的按鈕。這隻有在您生成報告的方式與我的相似時纔有效。基本上我拿報告,把它渲染成字節,並以pdf格式發送這些字節作爲響應。這將打開大多數瀏覽器如Chrome支持的PDF文件。這要求用戶採取額外步驟並點擊打印。

ServerReport sr = new ServerReport(); 
ReportViewer.ProcessingMode = ProcessingMode.Remote; 
sr = ReportViewer.ServerReport; 
sr.ReportServerUrl = new Uri("http://****/****"); 
sr.ReportPath = "/Report"; 
ReportParameter paramDateFrom = new ReportParameter(); 
ReportParameter paramDateTo = new ReportParameter(); 
ReportParameter paramState = new ReportParameter(); 
ReportParameter paramCounty = new ReportParameter(); 
string dateFrom = TB_Date_From.Text; 
string dateTo = TB_Date_To.Text; 
string state = DDL_State.SelectedValue; 
string county = DDL_County.SelectedValue; 
paramDateFrom.Name = "DateFrom"; 
paramDateFrom.Values.Add((dateFrom != "" ? dateFrom : null)); 
paramDateTo.Name = "DateTo"; 
paramDateTo.Values.Add((dateTo != "" ? dateTo : null)); 
paramState.Name = "State"; 
paramState.Values.Add((state != "" ? Common_Functions.resolveStateID(state) : null)); 
paramCounty.Name = "County"; 
paramCounty.Values.Add((county != "" ? Common_Functions.resolveCountyID(county) : null)); 
ReportViewer.ServerReport.SetParameters(new ReportParameter[] { paramDateFrom, paramDateTo, paramState, paramCounty }); 
// DUMP PDF TO BROWSER 
Warning[] warnings; 
string[] streamids; 
string mimeType, encoding, extension; 
byte[] bytes = ReportViewer.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings); 
Response.Buffer = true; 
Response.Clear(); 
Response.ContentType = mimeType; 
Response.AddHeader("content-disposition", "inline; filename=myfile." + extension); 
Response.BinaryWrite(bytes); 
string pdfPath = Server.MapPath("~") + "pdf." + extension; 
FileStream pdfFile = new FileStream(pdfPath, FileMode.Create); 
pdfFile.Write(bytes, 0, bytes.Length); 
pdfFile.Close(); 
Response.Flush(); 
Response.End();