adopilot adopilot - 1 year ago 120
ASP.NET (C#) Question

Send SQL Report in E mail attachment using C# and ASP.NET

I am trying to send report from sql reportserver 2008 as e mail attachment using ASP.NET and C#,
Till now I learned how to Get report as PDF in my code ,
Now I wanna combine line of codes like

byte[] bytes = rview.ServerReport.Render(format, deviceInfo, out mimeType, out encoding, out extension, out streamids, out warnings);
Response.OutputStream.Write(bytes, 0, bytes.Length);
Attachment reportAttachment = new Attachment(Response.OutputStream.Write(bytes,0,bytes.Length),"ado"); //Here I go wrong

Thanx in advance

Answer Source

Maybe I getting this wrong (I know little about SSRS) but I think you should

  1. Save the file to the file system

    System.IO.File.WriteAllBytes("c:\temp\temp.pdf", bytes);
  2. Send the file by email

    MailMessage mail = new MailMessage();
    mail.From        = "Me";
    mail.To          = "You";
    mail.Subject     = "Subject";
    mail.Body        = "Body";
    mail.BodyFormat  = MailFormat.Html;
    mail.Attachments.Add(new MailAttachment("c:\temp\temp.pdf"));
    catch(Exception ex)
       Response.Write("Ouch! " + ex.Message);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download