Tuesday, June 24, 2014

asp.net mvc generate rdlc/Excel to pdf report

You can follow the code:


  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);  
       }  
       ReportDataSource rds = new ReportDataSource("dsCustomerPackageInfo", tableObj);  
       ReportViewer localReport = new ReportViewer();  
       localReport.ProcessingMode = ProcessingMode.Local;  
       localReport.LocalReport.ReportPath = Server.MapPath("~/Reports/Billing/rdlc/rptCustomerPackageInfo.rdlc");  
       localReport.LocalReport.DataSources.Add(rds); // Add datasource here  
       string reportType = "PDF";  // You can change type
       string mimeType;  
       string encoding;  
       string fileNameExtension;  
       //The DeviceInfo settings should be changed based on the reportType  
       //http://msdn2.microsoft.com/en-us/library/ms155397.aspx  
       string deviceInfo =  
       "<DeviceInfo>" +  
       " <OutputFormat>PDF</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 = localReport.LocalReport.Render(  
         reportType,  
         null,  
         out mimeType,  
         out encoding,  
         out fileNameExtension,  
         out streams,  
         out warnings);  
       Response.Clear();  
       Response.ContentType = mimeType;  
       Response.AddHeader("content-disposition", "attachment; filename=CustomerPackageInformation." + fileNameExtension);  
       Response.BinaryWrite(renderedBytes);  
       Response.End();  
       Response.Flush();  
       return View(CustomerPackageReportViewModel);  
     }  


Ensure that this project has Microsoft.Bcl.Build installed and packages.config is located next to the project file

In my Xamarin form application their was dependency Restclient on Microsoft.Bcl.Build Microsoft.Bcl. i just remove all using nuget and ...