protected void btnExcel_Click(object sender, ImageClickEventArgs e)
{
ExportReport("Excel");
}
private void ExportReport(string ReportType)
{
try
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
String deviceInfo;
deviceInfo = "True";
if (ReportType == "Excel")
{
deviceInfo = "<deviceinfo>" + "<simplepageheaders>True</simplepageheaders>" + "</deviceinfo>";
}
else if (ReportType == "pdf")
{
deviceInfo = "<deviceinfo>" + "<simplepageheaders>True</simplepageheaders>" + "</deviceinfo>";
}
byte[] bytes = ReportViewer1.ServerReport.Render(
ReportType, deviceInfo, out mimeType, out encoding, out extension,
out streamids, out warnings);
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + filename + "." + extension);
Response.BinaryWrite(bytes);
Response.Flush();
}
catch (System.Exception em)
{
Exception inner = em.InnerException;
while ((inner != null))
{
inner = inner.InnerException;
}
}
}
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment