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

I have logic that download crystal-report, the issue is the report returns when dowloaded with no record of any data i have from the database.

What I have tried:

//GET/Download_Report

        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);
           // rpt.Refresh();
           


            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
Updated 6-Aug-20 5:05am
Comments
Sandeep Mewara 6-Aug-20 10:59am    
Have a look at how to run a crystal report programmatically: http://www.thescarms.com/dotnet/CrystalRptViewer.aspx

1 solution

 
Share this answer
 

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