Hi gandhipriyans,
Using the article i have created the example.
Export RDLC Report to PDF without using ReportViewer in ASP.Net with C# and VB.Net
Refer the below sample.
HTML
<asp:ScriptManager runat="server" />
<asp:Button ID="btnExport" Text="Export" runat="server" OnClick="Export" />
<rsweb:ReportViewer ID="ReportViewer1" runat="server" Width="100%"></rsweb:ReportViewer>
Namespaces
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.Reporting.WebForms;
Code
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
ReportViewer1.LocalReport.EnableHyperlinks = true;
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = Server.MapPath("~/Report.rdlc");
Customers dsCustomers = GetData("SELECT TOP 5 CustomerId,ContactName,City,Country FROM Customers");
ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
}
}
protected void Export(object sender, EventArgs e)
{
Warning[] warnings;
string[] streamIds;
string contentType;
string encoding;
string extension;
byte[] bytes = ReportViewer1.LocalReport.Render("PDF", null, out contentType, out encoding, out extension, out streamIds, out warnings);
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = contentType;
Response.AppendHeader("Content-Disposition", "attachment; filename=RDLC." + extension);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
private Customers GetData(string query)
{
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlDataAdapter sda = new SqlDataAdapter(query, con))
{
using (Customers dsCustomers = new Customers())
{
sda.Fill(dsCustomers, "DataTable1");
return dsCustomers;
}
}
}
}
Screenshot
