Dim msg As New Net.Mail.MailMessage(txtFrom.Text,txtTo.Text,txtSubject.Text,txtMessage.Text)
If fileUpload.PostedFile.FileName = "" Then
msg.Attachments.Add( New System.Net.Mail.Attachment(fileUpload.PostedFile.FileName))
taken from this stupid site He didn't even bother to use fileUpload.HasFile to check if the control has any file attached to it but use .Filename ="" instead. Either lazy or stupid programmer.
At the end I managed to find a solution which I think it's the best for my situation which I can't upload the file to a folder those, by using stream I can attach the file without even executing any IO to the disk. Superb!!
if (attachFile.PostedFile != null &&attachFile is a FileUpload control and email is a MailMessage class. :) You can read the whole solution here
attachFile.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 =
// attachFile.PostedFile exposes a System.IO.Stream
// property named InputStream
Attachment emailAttach = new Attachment(
tempFileName[tempFileName.Length - 1]);