2

Since I have not been able to intercept the events "print" and "export" of report viewer in asp.net (my previous question). I am now considering to trigger programmatically these two functions using buttons.

Is there anyone that has been able to achieve this in a report viewer asp.net? I mean to trigger "print" and "export to pdf" in the report viewer where these controls are set to non visible?

Community
  • 1
  • 1
FeliceM
  • 4,163
  • 9
  • 48
  • 75

2 Answers2

0

ReportViewer1.PrintDialog() seems to work. I'm not sure about export though.

SlicedBread
  • 67
  • 1
  • 8
0

Export:

private void DoExport(string exportType) {
  Warning[] warnings;
  string[] streamids;
  string mimeType;
  string encoding;
  string extension;
  string filename;

  byte[] bytes = reportViewer.LocalReport.Render(
     exportType, null, out mimeType, out encoding,
      out extension,
     out streamids, out warnings);

  filename = string.Format("report-{0:yyyy-MM-dd}.{1}", DateTime.Now, extension);
  Response.ClearHeaders();
  Response.Clear();
  Response.AddHeader("Content-Disposition", "attachment;filename=" + filename);
  Response.ContentType = mimeType;
  Response.BinaryWrite(bytes);
  Response.Flush();
  Response.End();
}

protected void btnExportToExcel_Click(object sender, EventArgs e) {
  DoExport("Excel");
}

protected void btnExportToPdf_Click(object sender, EventArgs e) {
  DoExport("Pdf");
}

Not sure about the print (how can you trigger client side functionality on server anyway ? ;)

Ondrej Svejdar
  • 21,349
  • 5
  • 54
  • 89