开发者

email attatchment winds up being 0,0 kb

开发者 https://www.devze.com 2023-02-05 05:30 出处:网络
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

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:

  1. I'm using the FileContent property of the FileUpload control (although it seems that it's just an alias to PostedFile.InputStream).
  2. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消