public ActionResult ExportReport() { List <Book> allEverest = new List <Book>(); using (EventManagementDbContaxt dc = new EventManagementDbContaxt()) { allEverest = dc.Books.ToList(); } ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/CrystalReport"), "CrystalReport1.rpt")); rd.SetDataSource(allEverest); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); try { Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); return(File(stream, "application/pdf", "EverestList.pdf")); } catch (Exception ex) { throw; } }
public ActionResult Report(string id) { LocalReport lr = new LocalReport(); string path = Path.Combine(Server.MapPath("~/Report"), "Report1.rdlc"); if (System.IO.File.Exists(path)) { lr.ReportPath = path; } else { return(View("Index")); } List <Hall> cm = new List <Hall>(); using (EventManagementDbContaxt dc = new EventManagementDbContaxt()) { cm = dc.Halls.ToList(); } ReportDataSource rd = new ReportDataSource("HallsData", cm); lr.DataSources.Add(rd); string reportType = id; string mimeType; string encoding; string fileNameExtension; string deviceInfo = "<DeviceInfo>" + " <OutputFormat>" + id + "</OutputFormat>" + " <PageWidth>8.5in</PageWidth>" + " <PageHeight>11in</PageHeight>" + " <MarginTop>0.5in</MarginTop>" + " <MarginLeft>1in</MarginLeft>" + " <MarginRight>1in</MarginRight>" + " <MarginBottom>0.5in</MarginBottom>" + "</DeviceInfo>"; Warning[] warnings; string[] streams; byte[] renderedBytes; renderedBytes = lr.Render( reportType, deviceInfo, out mimeType, out encoding, out fileNameExtension, out streams, out warnings); return(File(renderedBytes, mimeType)); }