public partial class _Default : System.Web.UI.Page
{
String m_currentReport;
private void saveRptAs(String s_rptType)
{
Warning[] warnings;
string[] streamids;
string mimeType;
string encoding;
string extension;
// string deviceInfo;
byte[] bytes = ReportViewer1.ServerReport.Render(
s_rptType, null, out mimeType, out encoding, out extension,
out streamids, out warnings);
/*
FileStream stream = File.OpenWrite(@"C:\Documents and Settings\michael.shorten\Local
Settings\Temp\sample.pdf");
stream.Write(bytes, 0, bytes.Length);
stream.Close();
*/
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=sample."+extension);
Response.BinaryWrite(bytes);
Response.Flush();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!(Request.QueryString["rpt"]== null))
{
m_currentReport = Request.QueryString["rpt"].ToString();
showReport(m_currentReport);
}
}
private void showReport(string sReportPath)
{
// Set Processing Mode
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
// Set Report Server and path
ReportViewer1.ServerReport.ReportServerUrl = new Uri(http://localhost/ReportServer);
ReportViewer1.ServerReport.ReportPath = sReportPath;
}
protected void btnSaveExcel_Click(object sender, EventArgs e)
{
saveRptAs("Excel");
}
protected void btnSavePDF_Click(object sender, EventArgs e)
{
saveRptAs("PDF");
}
}