Click here to Skip to main content
14,106,748 members
Click here to Skip to main content
Add your own
alternative version


42 bookmarked
Posted 29 Dec 2008
Licenced CPOL

Send Mail and Print Report in Report Viewer Control

, 29 Dec 2008
Rate this:
Please Sign up or sign in to vote.
This article demonstrates the implementation of Print and Send Mail operation in Report Viewer


I have been working with Report Viewer and have come across a lot of problems related to print option and mailing reports as an attachment to end users. This article aims to help developers facing similar problems.

Bind RDLC -to Report Viewer

Please refer to the following article:

Send Mail Attachment of Report in Report Viewer

One can drag the button and code the lines below so as to send a report as an attachment. In the code below, the attachment can be PDF, HTML, DOC, Excel, etc. For PDF, one needs to code reportViewer.LocalReport.Render("PDF", null,... The code here is self explanatory.

using System.Net.Mail;
private void SendMail(ReportViewer reportViewer)
            Warning[] warnings;
            string[] streamids;
            string mimeType;
            string encoding;
            string extension;

            byte[] bytes = reportViewer.LocalReport.Render
		("Excel", null, out mimeType, out encoding, out extension, out 
		streamids, out warnings);

            MemoryStream memoryStream = new MemoryStream(bytes);
            memoryStream.Seek(0, SeekOrigin.Begin);

            MailMessage message = new MailMessage();
            Attachment attachment = new Attachment(memoryStream,"BusinessReport.xls");

            message.From = new MailAddress("");

            message.Subject = "Business Report";
            message.IsBodyHtml = true;

            message.Body = "Please find Attached Report herewith."
            if (ConfigurationManager.AppSettings["SendMail"].ToString() == "Y")
                SmtpClient smtp = new SmtpClient("SMTP Server Name");        
		//This is for testing.
		SmtpClient smtp = new SmtpClient();        


Design HTML

< rsweb:ReportViewer ID="ReportViewer1" runat="server" 

	Font-Names="Verdana" Font-Size="8pt"

                <LocalReport ReportPath="Report.rdlc" >
                   <DataSources >
                        < rsweb:ReportDataSource / >
                    </DataSources >
                </LocalReport >
            </rsweb:ReportViewer >  

Web Configuration

One can test this code snippet by adding the below configuration in web config.

< >
    < mailSettings >
   	< smtp deliveryMethod="SpecifiedPickupDirectory" >
    	     < specifiedPickupDirectory pickupDirectoryLocation="C:\Test\" / >
	</smtp >
</ >  

Print Operation in Report Viewer

Please refer to the link below:


Hope I met the expectation of developers working on similar problems.


  • 29th December, 2008: Initial post 


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

santosh poojari
Technical Lead
Australia Australia
Whatsup-->Exploring--> MVC/HTML5/Javascript & Virtualization.......!

You may also be interested in...


Comments and Discussions

GeneralMy vote of 1 Pin
David Catriel2-Feb-14 10:43
memberDavid Catriel2-Feb-14 10:43 
SuggestionPrint report without preview Pin
mic2128-May-13 1:35
membermic2128-May-13 1:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190518.1 | Last Updated 29 Dec 2008
Article Copyright 2008 by santosh poojari
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid