FileUpload overført til E-mail
Jeg har en aspx form der benyttes til at sende informationer tilen e-mail
Jeg skal have en uploded fil sendt som attaced file
Hvordan får jeg : "File uploaded!" lagt over i txtAttach.Text
Se nedenfor: txtAttach.Text = "File uploaded!" <===
If IsPostBack Then
Dim path As String = Server.MapPath("~/UploadedImages/")
Dim fileOK As Boolean = False
If FileUpload1.HasFile Then
Dim fileExtension As String
fileExtension = System.IO.Path. _
GetExtension(FileUpload1.FileName).ToLower()
Dim allowedExtensions As String() = _
{".jpg", ".jpeg", ".png", ".gif"}
For i As Integer = 0 To allowedExtensions.Length - 1
If fileExtension = allowedExtensions(i) Then
fileOK = True
End If
Next
If fileOK Then
Try
FileUpload1.PostedFile.SaveAs(path & _
FileUpload1.FileName)
txtAttach.Text = "File uploaded!" <===
Catch ex As Exception
txtAttach.Text = "File could not be uploaded."
End Try
Else
txtAttach.Text = "Cannot accept files of this type."
End If
End If
End If
Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim sKontaktNavn As String, sFirma As String, sAdresse As String, sTlf As String
Dim sTo As String, sFrom As String, sSubject As String, sBody As String
Dim sAttach As String
Dim iLoop1 As Integer
sAttach = Trim(txtAttach.Text)
' Build an IList of mail attachments.
If sAttach <> "" Then
Dim delim As Char = ","
Dim sSubstr As String
For Each sSubstr In sAttach.Split(delim)
Dim myAttachment As MailAttachment = New MailAttachment(sSubstr)
MyMail.Attachments.Add(myAttachment)
Next
End If
SmtpMail.SmtpServer = sMailServer
SmtpMail.Send(MyMail)
End Sub