Monthly Archives: September 2020

how to generate report from c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Reporting.WebForms;
using Microsoft.ReportingServices.DataProcessing;

namespace WebApplication3
public partial class run_report1 : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)


public void ExportToPDF(string path, List<ReportParameter> reportParams, string fileName)

Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;

// Setup the report viewer object and get the array of bytes
var viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Remote;
viewer.ServerReport.ReportServerUrl = new Uri(“http://localhost/ReportServer”);
viewer.ServerReport.ReportPath = “/” + path;

byte[] bytes = viewer.ServerReport.Render(“PDF”, null, out mimeType, out encoding, out extension,
out streamIds, out warnings);

// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.ContentType = mimeType;
Response.AddHeader(“content-disposition”, “attachment; filename=” + fileName + “.” + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush(); // send it to the client to download