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.
private void SendMail(ReportViewer reportViewer)
byte bytes = reportViewer.LocalReport.Render
("Excel", null, out mimeType, out encoding, out extension, out
streamids, out warnings);
MemoryStream memoryStream = new MemoryStream(bytes);
MailMessage message = new MailMessage();
Attachment attachment = new Attachment(memoryStream,"BusinessReport.xls");
message.From = new MailAddress("email@example.com");
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");
SmtpClient smtp = new SmtpClient();
< rsweb:ReportViewer ID="ReportViewer1" runat="server"
<LocalReport ReportPath="Report.rdlc" >
< rsweb:ReportDataSource / >
One can test this code snippet by adding the below configuration in web config.
< system.net >
< mailSettings >
< smtp deliveryMethod="SpecifiedPickupDirectory" >
< specifiedPickupDirectory pickupDirectoryLocation="C:\Test\" / >
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