Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Team

I have a logic that download excel file report using crystal-report, but there is no data and dont know what could be an issue. On the database column there is data from the table column. What could be the reason for my file be empty when its downloading?

What I have tried:

public ActionResult Download_ExcelReport()
        {
            //var _db = new eNtsaRegistration();

            var data = (from q in db.eNtsaRegForms select new { 
            Id = q.Id,
            FirstName = q.FirstName!=null?q.FirstName:""
            
            }).ToList();

            ReportDocument rpt = new ReportDocument();
            rpt.Load(Server.MapPath("~/Reports/uYiloReporting.rpt"));
            rpt.SetDataSource(data);


            Response.Buffer = false;
            Response.ClearContent();
            Response.ClearHeaders();

            try
            {
                Stream stream = rpt.ExportToStream(CrystalDecisions.Shared.ExportFormatType.Excel);
                stream.Seek(0, SeekOrigin.Begin);
                return File(stream, "application/vnd.ms-excel", "eNtsaRegistrationForm.xls");
            }
            catch
            {
                throw;
                return View();
            }

           
        }
Posted

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