The Report Writer is a class library that is used to export the RDL report with popular file formats like PDF, Microsoft Word, Microsoft CSV, and Microsoft Excel without previewing the report on a webpage. This section describes how to export the RDL report to an ASP.NET application using the Report Writer
.
BoldReports.Web
package, and install this in your application.The following table provides details about the dependency packages and their usage.
Package | Purpose |
---|---|
Syncfusion.Pdf.AspNet |
Exports the report to a PDF. |
Syncfusion.DocIO.AspNet |
Exports the report to a Word. |
Syncfusion.XlsIO.AspNet |
Exports the report to an Excel. |
Syncfusion.Presentation.AspNet |
Exports the report to a PowerPoint. |
Newtonsoft.Json |
Serializes and deserializes data for the Report Writer. It is a mandatory package for Report Writer, and the package version should be 10.0.1 or higher. |
In this tutorial, the
sales-order-detail.rdl
report is used and it can be downloaded here. You can get the reports from the Bold Reports installation location. For more information, refer to samples and demos section.
Create a folder Resources
in your application. Copy and paste the sample RDL reports into the Resources
folder.
Open Default.aspx.cs
and add the following using namespace.
using BoldReports.Writer;
Initialize the Report Writer using the following code example.
protected void ExportButton_Click(object sender, EventArgs e)
{
string fileName = null;
WriterFormat format;
HttpContext httpContext = System.Web.HttpContext.Current;
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
writer.ReportPath= Server.MapPath("~/Resources/sales-order-detail.rdl");
if (this.ExportFormat.SelectedValue == "PDF")
{
fileName = "sales-order-detail.pdf";
format = WriterFormat.PDF;
}
else if (this.ExportFormat.SelectedValue == "Word")
{
fileName = "sales-order-detail.docx";
format = WriterFormat.Word;
}
else if (this.ExportFormat.SelectedValue == "Html")
{
fileName = "sales-order-detail.Html";
format = WriterFormat.HTML;
}
else if (this.ExportFormat.SelectedValue == "PPT")
{
fileName = "sales-order-detail.ppt";
format = WriterFormat.PPT;
}
else
{
fileName = "sales-order-detail.xlsx";
format = WriterFormat.Excel;
}
writer.Save(fileName, format, httpContext.Response);
}
Open the Default.aspx
home page. Replace the following code snippet on the Default.aspx
home page. Ensure that inherits value is same for application name Inherits="<application name>._Default"
.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebformsWriter._Default" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title> BoldReports Writer </title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Add the following code example in the <body>
tag of the Default.aspx page to view Report Writer export options.
<body>
<div class="container">
<div class="content_section">
<form id="form1" runat="server">
<div id="description_Pane" style="text-align: justify;">
<h3>Description</h3>
<span>
Bold ReportWriter is a powerful control for exporting RDL and RDLC files into specified
format files.
</span>
</div>
<div id="export_Pane" style="margin-top: 4%;">
<h3>Export Report</h3>
<span>
Choose a file format to view the selected document generated from Report file by using Essential ReportWriter.
</span>
<div id="selection_Pane" style="margin-top: 2%;">
<asp:Label Style="font-size: large;" runat="server">
Save As :
</asp:Label>
<asp:RadioButtonList RepeatLayout="Flow" ID="ExportFormat" RepeatDirection="Horizontal" runat="server">
<asp:ListItem Selected="True">PDF</asp:ListItem>
<asp:ListItem>Word</asp:ListItem>
<asp:ListItem>Excel</asp:ListItem>
<asp:ListItem>Html</asp:ListItem>
<asp:ListItem>PPT</asp:ListItem>
<asp:ListItem>csv</asp:ListItem>
</asp:RadioButtonList>
<asp:Button style="width: 18%; margin-left: 2%;" ID="ExportButton" runat="server" OnClick="ExportButton_Click" Text="Generate" />
</div>
</div>
</form>
</div>
</div>
</body>
Now, run and export the report with a specified export format in your Report Writer application.
Congratulations! You have completed your first Web Forms Writer application! Click here to download the already created WEB Forms Report Writer application.
Note: You can refer to our feature tour page for the ASP.NET Web Forms Report Writer to see its innovative features. Additionally, you can view our ASP.NET Web Forms Report Writer examples which demonstrate the rendering of SSRS RDLC and RDL reports.