Hello,
I have an NBISIAReport.rdlc file in MVC and i want to change the title of the report like 'Bridge NBI SIA Report' but title comes like 'NBISIAReport' when i downloaded the report.
Here is my code,
- [HttpPost]
- public ActionResult GenerateMultipleNBISIAReport(List<NBISIAReportViewModel> structures)
- {
- try
- {
-
- DateTime currDate = DateTime.Now;
- string dirName = "NBI-SIA_Reports" + "_" + currDate.ToString("MM") + "_" + currDate.ToString("dd") + "_" + currDate.ToString("yy") + "_" + currDate.ToString("HH") + "_" + currDate.ToString("mm");
- var reportFolderPath = Request.MapPath(Request.ApplicationPath) + "Downloads/" + dirName;
- const string fileExtension = "PDF";
- var zipFolderPath = reportFolderPath + "/" + dirName + ".zip";
- var exists = Directory.Exists(reportFolderPath);
- if (!exists)
- {
- Directory.CreateDirectory(reportFolderPath);
- }
- else
- {
- Directory.Delete(reportFolderPath, true);
- Directory.CreateDirectory(reportFolderPath);
- }
- foreach (var structure in structures)
- {
- if (structure.Id == null) continue;
- string reportName;
- string reportPath;
- string reportTitle;
- switch (structure.StrKindCode)
- {
- case "1":
- reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";
- reportName = structure.StrNumber + "-Bridge.pdf";
- break;
- case "2":
- reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";
- reportName = structure.StrNumber + "-Culvert.pdf";
- break;
- case "3":
- reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";
- reportName = structure.StrNumber + "-Tunnel.pdf";
- break;
- case "4":
- reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";
- reportName = structure.StrNumber + "-Trail.pdf";
- break;
- default:
- reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";
- reportName = structure.StrNumber + "-Other.pdf";
- break;
- }
- var localReport = new LocalReport {
- ReportPath = reportPath };
- var obj = new InspectionReportData();
- var ds = obj.GetNBISIAReportData(Convert.ToInt32(structure.Id), AgencyCode);
- localReport.DataSources.Add(new ReportDataSource("NBISIAReportDataSet", ds.Tables[0]));
- localReport.DataSources.Add(new ReportDataSource("NBISIABIPReportDataSet", ds.Tables[1]));
- localReport.EnableExternalImages = true;
- localReport.DisplayName = reportTitle;
- var renderByte = localReport.Render(fileExtension, "");
- localReport.DisplayName='Bridge NBI SIA Report';
- using (var fileStream = new FileStream(reportFolderPath + "/" + reportName, FileMode.Create))
- {
- fileStream.Write(renderByte, 0, renderByte.Length);
- }
- }
- using (var zip = new ZipFile())
- {
- zip.AddDirectory(reportFolderPath);
- zip.Save(zipFolderPath);
- }
- dirName = string.Empty;
- return Json(new { success = true, filePath = zipFolderPath }, JsonRequestBehavior.AllowGet);
- }
- catch (Exception ex)
- {
- return Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet);
- }
- }