ASP.NET MVC Generate Crystal report to pdf

See the code sample:

   public ActionResult GenerateReport(CustomerPackageReportViewModel CustomerPackageReportViewModel)  
     {  
       List<CustomerPackageDetailsReportViewModel> _customerList = (List<CustomerPackageDetailsReportViewModel>)Session["CustomerPackageInfo"];  
       DataTable tableObj = new DataTable();  
       if (_customerList!=null)  
       {  
         tableObj = Converter.ToDataTable(_customerList);  
       }  
       else  
       {  
         tableObj = Converter.ToDataTable(ArchitectureList);  
       }  
         ReportDocument reportDoc = new ReportDocument();  
         string rptPath = "";  
         rptPath = Server.MapPath("~/Reports/Billing/Crystal/rptCustomerPackage.rpt");  
         reportDoc.Load(rptPath);  
         reportDoc.SetDataSource(tableObj);  
         Stream reportStream = this.ConvertReportToPDF(reportDoc);  
         return new FileStreamResult(reportStream, "application/pdf");  
     }  
  [NonAction]  
     public Stream ConvertReportToPDF(ReportDocument DocReport)  
     {  
       if (DocReport == null)  
       {  
         return null;  
       }  
       return DocReport.ExportToStream(ExportFormatType.PortableDocFormat);  
     }            


Popular posts from this blog

WPF Crystal Report Viewer Using SAP

ASP.NET MVC razor SAP Crystal report