Im making an emailng function and all works like a charm LOCALLY. But when i take it to the webserver the email attatchment is 0,0kb.. i figured it has something to do with the stream but i doesnt get any error-messages so its hard to tell. I cant use the stream on my server? Heres the code:
If FileUpload1.HasFile = True Then
Dim tempFileName As String() = FileUpload1.PostedFile.FileName.Split("\"c)
Dim emailAttach As New Attachment(FileUpload1.PostedFile.InputStream, tempFileName(tempFileName.Length - 1))
message.Attachments.Add(emailAttach)
emailAtt开发者_StackOverflow中文版ach.Dispose()
End If
Tried several things but cant find out why there is a problem
Try the following:
message.Attachments.Add(New Attachment(FileUpload1.FileContent, tempFileName(tempFileName.Length - 1), FileFileUpload1.PostedFile.ContentType)
Remarks:
- I'm using the FileContent property of the
FileUpload
control (although it seems that it's just an alias toPostedFile.InputStream
). - I'm specifying the MIME type of the file (third parameter of the constructor).
Also the problem might be because you make a call to Dispose method which (according to Reflector) closes the input stream.
精彩评论