Here we go - to render the rdlc local report in asp.net web application
public static void GenerateExcelFromLocalReport()
{
//get your report datasource from the database
IDataReader iReader = GetReportDataSourceReader();
LocalReport report = new LocalReport();
report.ReportPath = HttpContext.Current.Server.MapPath("~/reports
/rdlc/MyReport.rdlc");
report.DataSources.Add(new ReportDataSource("DataSource1", iReader));
ReportParameter[] parameters = new ReportParameter[3];
parameters[0] = new ReportParameter("Filter1", "Filter1's value"));
parameters[1] = new ReportParameter("Filter2", "Filter2's value");
parameters[2] = new ReportParameter("Footer", "Footer's value");
report.SetParameters(parameters);
//
//code to render report as excel document
string encoding = String.Empty;
string mimeType = String.Empty;
string extension = String.Empty;
Warning[] warnings = null;
string[] streamids = null;
//
byte[] byteArray = report.Render("Excel", null, out mimeType,
out encoding, out extension, out streamids, out warnings);
//
HttpContext.Current.Response.ContentType = "application/vnd.ms-excel";
HttpContext.Current.Response.AddHeader("Content-Disposition",
"attachment; filename=MyExcel.xls");
HttpContext.Current.Response.AddHeader("Content-Length",
byteArray.Length.ToString());
HttpContext.Current.Response.ContentType = "application/octet-stream";
HttpContext.Current.Response.BinaryWrite(byteArray);
HttpContext.Current.Response.End();
}
-::HTH::-
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment