Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ReportViewer and MailMessage

1 view
Skip to first unread message

abcd

unread,
Nov 9, 2009, 1:47:36 PM11/9/09
to
I am using MailMessage and ReportViewer.I am using below code snippet, my problem is that I get the email and it has attachment Temp.pdf, but the attachment doesnt open.
 
=========
byte[] buffer = ReportViewer1.LocalReport.Render("pdf", null, out mimeType, out encoding, out extension, out streamids, out warnings);
var f = System.IO.Path.GetTempFileName();
f = System.IO.Path.ChangeExtension(f, extension);
var fs = new FileStream(f, FileMode.Create);
fs.Write(buffer, 0, buffer.Length);
ContentType ct = new ContentType(MediaTypeNames.Application.Pdf);
var at = new Attachment(fs, ct);
at.ContentDisposition.FileName = "Temp.pdf";
at.ContentDisposition.DispositionType = DispositionTypeNames.Attachment;
msg.Attachments.Add(at);
           
smtpClient.Send(msg);
=============================
 
It says - "dobe reader could not open 'Temp.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attchment and wasn't correctly decoded)."
 
What could be wrong in my code. I get buffer filled up with 11342 bytes
 
Thanks in advance....

dotNetDave

unread,
Nov 11, 2009, 3:06:11 PM11/11/09
to
Well one thing I see is that your not using Flush then Close on the
FileStream before you attach it to the mail message. Try that.

David

======================================
David McCarter [Microsoft MVP]
www.dotNetTips.com
David McCarter''''s .NET Coding Standards available at:
http://codingstandards.notlong.com

0 new messages