FileUpload and mail sending

  • Thread starter Thread starter Qweertz
  • Start date Start date
Q

Qweertz

I'm trying to send e-mail with attachment that I take from FileUpload
control.
The problem is how to get full path of file.
For instance when I have file "C:\test.txt" FileUpload1.PostedFile.FileName
gets only "test.txt" and sending mail fails.

Can someone help?


Here's the code:

MailMessage mail = new MailMessage();
mail.From = "(e-mail address removed)";
mail.To = txtEmail.Text;
mail.Subject = "Anouncment about new Contract";
mail.Body = "Siging code is :" + txtSigningCode.Text;
mail.BodyFormat = MailFormat.Text;
mail.Attachments.Add(new MailAttachment(FileUpload2.PostedFile.FileName));
SmtpMail.Send(mail);
 
You'll probably have to save the uploaded file to your filesystem and attach
the saved file. Use PostedFile.SaveAs.
 
Back
Top