Next I would like to attach the file to an email. With FileUpload control I would do it as posted below. Is there an example that would work with UploadAttachments1 ? It should be even simpler than the code below.
if
(this.IsPostBack)
{
MailMessage email = new MailMessage();
email.From = new MailAddress("[email protected]");
email.To.Add(new MailAddress("[email protected]"));
email.Subject = "Test";
email.Body = "Test";
if (FileUpload1.PostedFile != null &&
FileUpload1.PostedFile.ContentLength > 0)
{
// attachFile.PostedFile.FileName contains
// the full path of the file. We only want the file
// so we delimit it by forward slashes into an array
string[] tempFileName =
FileUpload1.PostedFile.FileName.Split(
'\\');
// attachFile.PostedFile exposes a System.IO.Stream
// property named InputStream
Attachment emailAttach = new Attachment(FileUpload1.PostedFile.InputStream,tempFileNametempFileName.Length - 1]);
email.Attachments.Add(emailAttach);
}