How are you doing that...?
Thank you. I am using the example given at
http://aspalliance.com/794
I can put the string value (e.g. strMyAttachment) into a MemoryStream
object and create an Attachment as
UTF8Encoding utf8 = new UTF8Encoding();
byte[] myAttachmentBytes = utf8.GetBytes(strMyAttachment);
MemoryStream myAttachmentStream = new MemoryStream
(myAttachmentBytes );
Attachment attachment = new Attachment(myAttachmentStream ,
"myattachment.doc");
attachment.ContentType = new System.Net.Mime.ContentType
("application/msword");
Then add this attachment object to my MailMessage object and send it.
This is OK.
The problem: After I receive the email, I download the attachment to
my desktop, open it in MS Word, only to see the file presented in raw
HTML code with HTML tags. Users don't want to see this, they want to
see it rendered properly.
The button click event handler code is pasted here (same as that in
http://aspalliance.com/794).
protected void btnCreateWordDoc_Click(object sender, EventArgs e)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/
msword";
string strFileName = "GenerateDocument" + ".doc";
HttpContext.Current.Response.AddHeader("Content-
Disposition",
"inline;filename=" + strFileName);
StringBuilder strHTMLContent = new StringBuilder();
strHTMLContent.Append(" <h1 title='Heading'
align='Center'style='font-family: verdana; font -size: 80 % ; color:
black'><u>Document Heading</u> < / h1 > ".ToString());
strHTMLContent.Append("<br>".ToString());
strHTMLContent.Append(
"<table align='Center'>".ToString());
// Row with Column headers
strHTMLContent.Append("<tr>".ToString());
strHTMLContent.Append("<td style='width:100px; background:
#99CC00'><b>Column 1 < / b > < / td >".ToString());
strHTMLContent.Append("<td style='width:100px;background:
#99CC00'><b>Column 2 </b></td>".ToString());
strHTMLContent.Append("<tdstyle='width:100px; background:
#99CC00'><b>Column 3</b></td>".ToString());
strHTMLContent.Append("</tr>".ToString());
// First Row Data
strHTMLContent.Append("<tr>".ToString());
strHTMLContent.Append("<td style='width:100px'>a</
td>".ToString());
strHTMLContent.Append("<td style='width:100px'>b</
td>".ToString());
strHTMLContent.Append("<td style='width:100px'>c</
td>".ToString());
strHTMLContent.Append("</tr>".ToString());
// Second Row Data
strHTMLContent.Append("<tr>".ToString());
strHTMLContent.Append("<td style='width:100px'>d</
td>".ToString());
strHTMLContent.Append("<td style='width:100px'>e</
td>".ToString());
strHTMLContent.Append("<td style='width:100px'>f</
td>".ToString());
strHTMLContent.Append("</tr>".ToString());
strHTMLContent.Append("</table>".ToString());
strHTMLContent.Append("<br><br>".ToString());
strHTMLContent.Append("<p align='Center'> Note : This is
adynamically generated word document </p> ".ToString());
HttpContext.Current.Response.Write(strHTMLContent);
HttpContext.Current.Response.End();
HttpContext.Current.Response.Flush();
}