Barre horizontale de naviagtion

mercredi 3 novembre 2010

Export report view to PDF/EXCEL

  • Export PDF


public void ExportRerportToPDF(string FileNameOutput)
{
string mimeType;
string encoding;
string extension;
Warning[] warnings;
string[] streamids;
byte[] Bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);

#region save In DIsk
//FileStream fs = new FileStream(@"c:\" + FileNameOutput + "." + extension, FileMode.Create);
//fs.Write(Bytes, 0, Bytes.Length);
//fs.Close();
#endregion

#region View Immidiatly In Cuurent HTTP Flux
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = mimeType;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename="+FileNameOutput+"." + extension);
HttpContext.Current.Response.BinaryWrite(Bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
#endregion
}

  • Export Excel


public void ExportRerportToExcel(string FileNameOutput)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
string deviceInfo;
deviceInfo = "True";
byte[] bytes = ReportViewer1.LocalReport.Render("Excel", null, out mimeType, out encoding, out extension, out streamids, out warnings);

#region save In DIsk
FileStream fs =new FileStream(@"c:\" + FileNameOutput + ".xls", FileMode.Create);
fs.Write(bytes, 0, bytes.Length);
fs.Close();
#endregion

#region View Immidiatly In Cuurent HTTP Flux
HttpContext.Current.Response.Buffer = true;
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = mimeType;
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=" + FileNameOutput + "." + extension);
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.End();
#endregion

}

Aucun commentaire:

Enregistrer un commentaire