1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public ActionResult showReport(TradingDay tradingDay)
{
DataTable dt = new DataTable();
DateTime parsedDate = DateTime.ParseExact(tradingDay.TradingDate, "dd/MM/yyyy", CultureInfo.InvariantCulture);
// renommage du fichier pdf
string fileName = $"Rapport_{parsedDate:yyyyMMdd}.pdf";
var reportPath = Path.Combine(_hostingEnvironment.WebRootPath, "Rapport", "Rapport_Fr.rdlc");
if (!System.IO.File.Exists(reportPath))
{
return NotFound("Le fichier est introuvable.");
}
LocalReport report = new LocalReport();
using (var fs = System.IO.File.OpenRead(reportPath))
{
report.LoadReportDefinition(fs);
}
dt = GetData(parsedDate);
report.DataSources.Add(new ReportDataSource("DataSet1", dt));
var FormattedDateShort = parsedDate.ToShortDateString();
var param = new [] { new ReportParameter("date", FormattedDateShort)};
report.SetParameters(param);
byte[] pdf = report.Render("PDF");
return File(pdf, "application/pdf", fileName);
} |
Partager