This is a migrated thread and some comments may be shown as answers.

Reporting - EMail PDF Report Working Code

0 Answers 167 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Phil
Top achievements
Rank 1
Phil asked on 07 Jul 2015, 02:43 PM

After going through the many posts and examples I finally pieced together a functional MailReport function which I call from an UI for ASP.NET AJAX web application.  It is interesting to note the many ways of the process not working.

using System.IO;
using System.Net;
using System.Net.Mail;
using Telerik.Reporting.Processing;
 
 
        void MailReport(Telerik.Reporting.Report report, string from, string to, string subject, string body)
        {
            string extension = "pdf";
  
            System.Collections.Hashtable deviceInfo = new System.Collections.Hashtable();
 
            Telerik.Reporting.TypeReportSource typeReportSource =
                         new Telerik.Reporting.TypeReportSource();
            String smptHost = SMTPSender; //set this to your SMTP sender service host
             
            typeReportSource.TypeName = typeof(IRReport.IRReport).AssemblyQualifiedName;
            Telerik.Reporting.Processing.ReportProcessor reportProcessor = new Telerik.Reporting.Processing.ReportProcessor();
            Telerik.Reporting.Processing.RenderingResult result = reportProcessor.RenderReport("PDF", typeReportSource, deviceInfo);
            string fileName = result.DocumentName + "." + result.Extension;
            MemoryStream ms = new MemoryStream();
            ms.Write(result.DocumentBytes, 0, result.DocumentBytes.Length);
            ms.Position = 0;
            Attachment attachment = new Attachment(ms, report.Name + "." + extension);
            MailMessage msg = new MailMessage(from, to, subject, body);
            msg.Attachments.Add(attachment);
            SmtpClient client = new SmtpClient(smptHost);
            client.Send(msg);
        }

No answers yet. Maybe you can help?

Tags
General Discussions
Asked by
Phil
Top achievements
Rank 1
Share this question
or