.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Code Snippets >> ASP.NET Controls >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

port Rpt To PDF in ASP.NET

Posted By:Athira Sreejith       Posted Date: February 22, 2009    Points: 10    Category: ASP.NET Controls    URL: http://www.dotnetspark.com  

Export Rpt To PDF in ASP.NET Below is the sample code to export .RPT to PDF.

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using Microsoft.Reporting.WinForms;

using System.IO;

namespace SendMail


public partial class ExportRptToPDF : Form


public ExportRptToPDF()




private void ExportRptToPDF_Load(object sender, EventArgs e)





private void btnExport_Click(object sender, EventArgs e)



LocalReport localReport = new LocalReport();

localReport.ReportPath = @"C:\Documents and Settings\soumyam\My Documents\Visual Studio 2005\Projects\SendMail\SendMail\Report1.rdlc";

//A method that returns a collection for our report

//Note: A report can have multiple data sources

List employeeCollection = GetData();

//Give the collection a name (EmployeeCollection) so that we can reference it in our report designer

ReportDataSource reportDataSource = new ReportDataSource("EmployeeCollection", employeeCollection);


string reportType = "PDF";

string mimeType;

string encoding;

string fileNameExtension;

//The DeviceInfo settings should be changed based on the reportType


string deviceInfo =

"" +

" PDF" +

" 8.5in" +

" 11in" +

" 0.5in" +

" 1in" +

" 1in" +

" 0.5in" +


Warning[] warnings;

string[] streams;

byte[] renderedBytes;

//Render the report

renderedBytes = localReport.Render(



out mimeType,

out encoding,

out fileNameExtension,

out streams,

out warnings);


File.WriteAllBytes(@"D:\soumya\pdfexportedfile.pdf", renderedBytes);

//Clear the response stream and write the bytes to the outputstream

//Set content-disposition to "attachment" so that user is prompted to take an action

//on the file (open or save)


//Response.ContentType = mimeType;

//Response.AddHeader("content-disposition", "attachment; filename=foo." + fileNameExtension);







Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend