System.Web.Mail and PDF getting corrupted workaround
I was troubleshooting an issue where I was sending an email using .NET 1.1 and
attaching PDF files. The PDF files where getting an error when trying to open
the attachment. Here is what was displayed in Adobe reader.
"There was an error processing a page. A file I/O error has occurred".
Thanks a bunch to Dave Wanta, creator of
http://ASPNetEmail.com for providing a great resource about System.Web.Mail
( http://www.systemwebmail.com ).
A similar example worked in ASP.NET 2.0, comparing email headers provided the
clues it was how the attachment was getting encoded. I found the answer in the
article listed below.
This article explains it.
The bolded code is what you have to alter
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Mail" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
protected void Page_Load(object sender, EventArgs e)
string FilePath = Request.PhysicalApplicationPath + "/c.pdf";
MailMessage msgMail = new MailMessage();
msgMail.To = "steve@changethisBefore.com";
msgMail.From = "steve@changethisBefore.com";
msgMail.Subject = "Your Favorite Subject";
msgMail.Body = @"Some Text goes here";
<form id="form1" runat="server">
Hope this helps
Microsoft MVP - IIS