Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

What I have tried:

[HttpPost]
        public ActionResult GenerateMultipleNBISIAReport(List<NBISIAReportViewModel> structures)
        {
            try
            {
                //var dirName = User.Identity.Name.Replace(" ", "");
                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);
            }
        }
Posted
Comments
Richard Deeming 4-Mar-20 10:29am    
Why are you changing the DisplayName property after you've rendered the report?
adhikar patil 5-Mar-20 9:17am    
I want to just assign the title properties for the pdf file. So how this is possible? Please suggest me solution.
Richard Deeming 5-Mar-20 11:05am    
Try changing the DisplayName property before calling the localReport.Render method.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900