Hi Everyone,
I am Getting an error While Downloading a RDLC Report in MVC (Controller).
But Same Code is Working on ASPX Page
Error : Microsoft.ReportingServices.ReportProcessing.ReportProcessingException: The specified operation is not valid.
at : byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);
- void ReportDownLoad(string id)
- {
- scon = new SqlConnection(ConfigurationManager.ConnectionStrings["connection"].ConnectionString);
-
- ReportViewer ReportViewer1 = new ReportViewer();
- ReportViewer1.ProcessingMode = ProcessingMode.Local;
-
-
- ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report/SingleReport.rdlc");
-
- DataSet ds = new DataSet();
-
- SqlDataAdapter adapt = new SqlDataAdapter("SELECT * from table1 where id='"+id+"'", scon);
-
- adapt.Fill(ds, "DataTable1");
- scon.Close();
-
-
- ReportDataSource rds = new ReportDataSource("DataSet1", ds.Tables[0]);
- ReportViewer1.LocalReport.DataSources.Clear();
-
-
- ReportViewer1.LocalReport.DataSources.Add(rds);
-
-
-
- Warning[] warnings;
- string[] streamIds;
- string mimeType = string.Empty;
- string encoding = string.Empty;
- string extension = string.Empty;
- byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);
-
- Response.Buffer = true;
- Response.Clear();
- Response.ContentType = mimeType;
- Response.AddHeader("content-disposition", "attachment; filename= ReferenceNo" + id + ".pdf");
- Response.BinaryWrite(bytes);
- Response.Flush();
- }
Note Same Code is Working in ASPX Page.
Please Help me.