Export specific format report directly (Local Report)
时间:2011-02-14 来源:blair0807
代码 string
orderIDCollection
= "1,2,3";
//new a ReportViewer control
ReportViewer rview = new Microsoft.Reporting.WebForms.ReportViewer();
rview.ProcessingMode = ProcessingMode.Local;
rview.LocalReport.ReportPath = "rptOrder.rdlc";
rview.ExportContentDisposition = ContentDisposition.AlwaysAttachment;
//get datasource
List<OrderInfo> orderList = new List<OrderInfo>(GetOrderList(orderIDCollection));
//assign datasource for report
rview.LocalReport.DataSources.Add(
new Microsoft.Reporting.WebForms.ReportDataSource("OrderInfoDataSet",
orderList));
rview.LocalReport.Refresh();
string mimeType, encoding, extension, deviceInfo;
string[] streamids;
Microsoft.Reporting.WebForms.Warning[] warnings;
string format = "PDF";
//Desired format goes here (PDF, Excel, or Image)
deviceInfo ="<DeviceInfo>" +"<SimplePageHeaders>True</SimplePageHeaders>" +"</DeviceInfo>";
byte[] bytes = rview.LocalReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-disposition", "filename=output.pdf");
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.Close();
//new a ReportViewer control
ReportViewer rview = new Microsoft.Reporting.WebForms.ReportViewer();
rview.ProcessingMode = ProcessingMode.Local;
rview.LocalReport.ReportPath = "rptOrder.rdlc";
rview.ExportContentDisposition = ContentDisposition.AlwaysAttachment;
//get datasource
List<OrderInfo> orderList = new List<OrderInfo>(GetOrderList(orderIDCollection));
//assign datasource for report
rview.LocalReport.DataSources.Add(
new Microsoft.Reporting.WebForms.ReportDataSource("OrderInfoDataSet",
orderList));
rview.LocalReport.Refresh();
string mimeType, encoding, extension, deviceInfo;
string[] streamids;
Microsoft.Reporting.WebForms.Warning[] warnings;
string format = "PDF";
//Desired format goes here (PDF, Excel, or Image)
deviceInfo ="<DeviceInfo>" +"<SimplePageHeaders>True</SimplePageHeaders>" +"</DeviceInfo>";
byte[] bytes = rview.LocalReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-disposition", "filename=output.pdf");
Response.OutputStream.Write(bytes, 0, bytes.Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
Response.Flush();
Response.Close();
相关阅读 更多 +