/// <summary> /// 下载报表文件 /// </summary> /// <param name="s_rptType">打印的文件类型("Excel,PDF,Image")</param> public static void DowloadReportFile(HttpResponse response, ReportViewer rpvObject, ReportPrintType rptType, string fileName) { if (string.IsNullOrEmpty(fileName) || response == null || rpvObject == null) return; Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; byte[] bytes = rpvObject.LocalReport.Render( rptType.ToString(), null, out mimeType, out encoding, out extension, out streamids, out warnings); //Download response.Buffer = true; response.Clear(); response.ContentType = "application/" + extension; response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension); response.BinaryWrite(bytes); response.Flush(); response.End(); }
/// <summary> /// 保存报表文件为文件 /// </summary> /// <param name="rpvObject">Reportview控件实例</param> /// <param name="rptType">打印的文件类型</param> /// <param name="filePath">文件存放路径</param> /// <param name="fileName">文件名</param> public static void SaveReportFile(ReportViewer rpvObject, ReportPrintType rptType, string filePath, string fileName) { if (rpvObject == null || string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(filePath)) return; Warning[] warnings; string[] streamids; string mimeType; string encoding; string extension; byte[] bytes = rpvObject.LocalReport.Render( rptType.ToString(), null, out mimeType, out encoding, out extension, out streamids, out warnings); //file FileStream stream = new FileStream(filePath + fileName + "." + extension, FileMode.Create); stream.Write(bytes, 0, bytes.Length); stream.Close(); }