|
-
April 17th, 2009, 10:48 AM
#1
StreamWriter corrupting my RTF?
Basically, I want the user to fill out a form and have the RTF file updated with those values and then emailed as an attachment.
My code is as follows:
Code:
System.IO.StreamReader reader = new System.IO.StreamReader(Server.MapPath("~/GrantProposal/text2.rtf"));
string file = reader.ReadToEnd();
reader.Close();
file = file.Replace("gp1", frmDirector.Text);
file = file.Replace("gp2", frmPhone.Text);
System.IO.StreamWriter sw = new System.IO.StreamWriter(Server.MapPath("~/GrantProposal/text2.rtf"));
sw.Write(file);
sw.Flush();
sw.Close();
MailMessage mail = new MailMessage();
mail.To.Add(emailTo);
mail.From = new MailAddress(emailTo);
mail.Subject = "Grant Proposal";
//mail.Body = info;
Attachment attach = new Attachment(Server.MapPath("~/GrantProposal/text2.rtf"));
mail.Attachments.Add(attach);
SmtpClient smtpClient = new SmtpClient("localhost");
smtpClient.Send(mail);
When I test this, it emails the RTF fine, but when I download the attachment and try to open in Word, it gives me an error saying that the file is corrupted and data is either missing or invalid.
Any ideas?
I am using 3.5 if that helps..
Thanks
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|