Hola a todos, estoy tratando de enviar mails con archivos adjuntos pero me tope con el siguiente problema. Mi input file " <INPUT id="file01" type="file" name="file01" runat="server"> " no obtiene ningun valor y por esto no puedo enviar los archivos.
El codigo que tengo es el siguiente:
Private Sub envia_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles envia.Click
Label1.Text = ""
Dim mensaje As MailMessage = New MailMessage()
mensaje.From = TextBox1.Text
mensaje.To = "
[email protected]"
mensaje.Cc = "
[email protected]"
mensaje.Subject = "Documentación"
mensaje.Body = "Documentación de: " & TextBox2.Text
Dim attch As DBNull
Dim archtemp As DBNull
' Aqui es donde no logro obtener el contenido del input file, entonces me bota, el valor que tiene file01.postedfile es "Nothing" y no se porque, ya que la ruta del archivo ya la habia elejido por eje: C:\prueba.doc
If Not IsDBNull(file01.PostedFile) Then
Try
Dim attarch As HttpPostedFile = file01.PostedFile
Dim tamarch = attarch.ContentLength
If tamarch > 0 Or tamarch < 600 Then
Dim name = Path.GetFileName(file01.PostedFile.FileName)
attch = name
file01.PostedFile.SaveAs(Server.MapPath(name))
Dim archivo As MailAttachment = New MailAttachment(Server.MapPath(name))
mensaje.Attachments.Add(archivo)
Else
Label1.Text = "El archivo no puede ser anexado..."
End If
SmtpMail.SmtpServer.Insert(0, "127.0.0.1")
SmtpMail.Send(mensaje)
If Not IsDBNull(attch) Then
File.Delete(Server.MapPath(attch.ToString))
End If
TextBox1.Text = ""
TextBox2.Text = ""
Label1.Text = "El mensaje ha sido enviado"
Catch
Label1.Visible = True
Label1.Text = "Error"
TextBox1.Text = ""
TextBox2.Text = ""
End Try
End If
End Sub
yo tengo el Visual Studio 2002 con el Framework 1.0, no se si es por la version...
agradezco su ayuda porque ya tengo varios dias con esto y ya me empiezo a desesperar... Mil gracias y buen dia!