Step 1 – Create Crystal Report
IIn an MVC.NET project, on the root, create a folder for reports. Then, right click on that folder and select a new item. After that, create a Crystal Report file by following the below steps.
After clicking on the “Add” button, a new popup will open. In there, apply the below steps.
The Crystal Report will open like in the below image.
using CrystalDecisions.CrystalReports.Engine; using System; using System.Collections.Generic; using System.Data; using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Web; using System.Web.Mvc; using System.Xml.Linq; using temp.Models; namespace temp.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } public ActionResult Download_PDF() { empEntities context = new empEntities(); ReportDocument rd = new ReportDocument(); rd.Load(Path.Combine(Server.MapPath("~/Report"), "Emp_Data.rpt")); rd.SetDataSource(context.emp_table.Select(c => new { id = c.id, name = c.name }).ToList()); Response.Buffer = false; Response.ClearContent(); Response.ClearHeaders(); rd.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape; rd.PrintOptions.ApplyPageMargins(new CrystalDecisions.Shared.PageMargins(5, 5, 5, 5)); rd.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA5; Stream stream = rd.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat); stream.Seek(0, SeekOrigin.Begin); return File(stream, "application/pdf", "CustomerList.pdf"); } } }
ReportDocument rd = new ReportDocument();
rd.Load(Path.Combine(Server.MapPath("~/Report"), "Emp_Data.rpt"));
context.emp_table.Select(c => new
{
id = c.id,
name = c.name
}).ToList()
return File(stream, "application/pdf", "CustomerList.pdf");
<a href="Home/Download_PDF/" target="_blank" class="btn btn-primary" style="margin-top:20px;">Download_PDF</a>
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
View Comments
Hi:i used your code But the following commands become colored and give an error:{"DataSet does not support System.Nullable."}.
rd.SetDataSource(context.emp_table.Select(c => new
{
id = c.id,
name = c.name
}).ToList());
I changed it as follows, it still gives the same error
rd.SetDataSource(context.peaces.Select(c => new
{
ID = c.ID==null? 0 :c.ID,
//==null? 0 :c.ID,
code = c.code == null ? 0 : c.code,
//== null ? 0 : c.code,
kala = c.kala == null ? "0" : c.kala
}).ToList());
Please help me, my program needs reporting and I have been searching for a few days, I can not solve my problem.Thanks