Adhikar Patil

Adhikar Patil

  • 1.6k
  • 457
  • 80.4k

How can I change the title of rdlc report in MVC

Mar 4 2020 2:41 AM
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,
  1. [HttpPost]  
  2. public ActionResult GenerateMultipleNBISIAReport(List<NBISIAReportViewModel> structures)  
  3. {  
  4. try  
  5. {  
  6. //var dirName = User.Identity.Name.Replace(" ", "");  
  7. DateTime currDate = DateTime.Now;  
  8. string dirName = "NBI-SIA_Reports" + "_" + currDate.ToString("MM") + "_" + currDate.ToString("dd") + "_" + currDate.ToString("yy") + "_" + currDate.ToString("HH") + "_" + currDate.ToString("mm");  
  9. var reportFolderPath = Request.MapPath(Request.ApplicationPath) + "Downloads/" + dirName;  
  10. const string fileExtension = "PDF";  
  11. var zipFolderPath = reportFolderPath + "/" + dirName + ".zip";  
  12. var exists = Directory.Exists(reportFolderPath);  
  13. if (!exists)  
  14. {  
  15. Directory.CreateDirectory(reportFolderPath);  
  16. }  
  17. else  
  18. {  
  19. Directory.Delete(reportFolderPath, true);  
  20. Directory.CreateDirectory(reportFolderPath);  
  21. }  
  22. foreach (var structure in structures)  
  23. {  
  24. if (structure.Id == nullcontinue;  
  25. string reportName;  
  26. string reportPath;  
  27. string reportTitle;  
  28. switch (structure.StrKindCode)  
  29. {  
  30. case "1":  
  31. reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";  
  32. reportName = structure.StrNumber + "-Bridge.pdf";  
  33. break;  
  34. case "2":  
  35. reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";  
  36. reportName = structure.StrNumber + "-Culvert.pdf";  
  37. break;  
  38. case "3":  
  39. reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";  
  40. reportName = structure.StrNumber + "-Tunnel.pdf";  
  41. break;  
  42. case "4":  
  43. reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";  
  44. reportName = structure.StrNumber + "-Trail.pdf";  
  45. break;  
  46. default:  
  47. reportPath = Request.MapPath(Request.ApplicationPath) + @"Reports\NBISIAReport.rdlc";  
  48. reportName = structure.StrNumber + "-Other.pdf";  
  49. break;  
  50. }  
  51. var localReport = new LocalReport {  
  52. ReportPath = reportPath };  
  53. var obj = new InspectionReportData();  
  54. var ds = obj.GetNBISIAReportData(Convert.ToInt32(structure.Id), AgencyCode);  
  55. localReport.DataSources.Add(new ReportDataSource("NBISIAReportDataSet", ds.Tables[0]));  
  56. localReport.DataSources.Add(new ReportDataSource("NBISIABIPReportDataSet", ds.Tables[1]));  
  57. localReport.EnableExternalImages = true;  
  58. localReport.DisplayName = reportTitle;  
  59. var renderByte = localReport.Render(fileExtension, "");  
  60. localReport.DisplayName='Bridge NBI SIA Report';  
  61. using (var fileStream = new FileStream(reportFolderPath + "/" + reportName, FileMode.Create))  
  62. {  
  63. fileStream.Write(renderByte, 0, renderByte.Length);  
  64. }  
  65. }  
  66. using (var zip = new ZipFile())  
  67. {  
  68. zip.AddDirectory(reportFolderPath);  
  69. zip.Save(zipFolderPath);  
  70. }  
  71. dirName = string.Empty;  
  72. return Json(new { success = true, filePath = zipFolderPath }, JsonRequestBehavior.AllowGet);  
  73. }  
  74. catch (Exception ex)  
  75. {  
  76. return Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet);  
  77. }  
  78. }  

Answers (2)