static void Main(string[] args) { var connectionString = TestTaskConfiguration.Instance.ConnectionString; var context = new DataContext(connectionString); var repository = new EmployeeRepository(context); var service = new EmployeeService(repository); var node = new EmployeeReportModel(); node.EmployeeDetails = service.All().OrderBy(x => x.FirstName).Select(x => new EmployeeReportDetailsModel { Name = x.FirstName, Wage = x.Wage }).ToList(); dataList.Add(node); ReportViewer reportViewer = new ReportViewer(); reportViewer.ProcessingMode = ProcessingMode.Local; reportViewer.LocalReport.ReportPath = AppDomain.CurrentDomain.BaseDirectory + @"\..\..\EmployeeReportTemplate.rdlc"; reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(ReportViewer_OnSubreportProcessing); reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DSEmployee", dataList)); Byte[] result = reportViewer.LocalReport.Render("PDF"); using (FileStream fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + @"\Test.pdf", FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write)) { fs.Write(result, 0, result.Length); fs.Flush(); fs.Close(); } //Console.ReadKey(); }
public ActionResult GetReport() { var employees = _employeeService.All().Where(x => x.Status == EmployeeStatus.Active).OrderBy(x => x.FirstName).ToList() .Select(x => new EmployeeReportDetailsModel { Name = x.FirstName, Wage = x.Wage, Tax = _taxService.GetTax(x.Wage) }).ToList(); var employeeReportModel = new EmployeeReportModel { EmployeeDetails = employees }; employeeReport = new List<EmployeeReportModel> { employeeReportModel }; ReportViewer reportViewer = new ReportViewer(); reportViewer.ProcessingMode = ProcessingMode.Local; reportViewer.LocalReport.ReportPath = _pathProvider.MapPath(@"~\ReportTemplates\EmployeeReportTemplate.rdlc"); reportViewer.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(ReportViewer_OnSubreportProcessing); reportViewer.LocalReport.DataSources.Add(new ReportDataSource("DSEmployee", employeeReport)); Byte[] result = reportViewer.LocalReport.Render("PDF"); String fileName = "fileReport.pdf"; return File(result, System.Net.Mime.MediaTypeNames.Application.Pdf, fileName); }