The same code below on a sister - users have to scroll their browser. Here, the you scroll the code box.... This is only a test.
Code:
Imports System.Collections.Generic
Imports System.Text
Imports System.Net
Imports System.IO
Imports System.Net.Mail
Imports System.Data
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Dim xURL As String
Dim xImagenLocal As String
Dim xRutaImagenLocal As String
Dim xCarpetaImagenes As String
Dim xImagenNoImagen As String
Dim arrayArchivosParaBorrar() As String
Dim nn As Integer = 0
xRutaImagenLocal = Server.MapPath("") & "\"
xCarpetaImagenes = "imagenes\"
xImagenNoImagen = xRutaImagenLocal & xCarpetaImagenes & "nocamara.jpg" ' Use this image when the camera doesn't respond.
' Preparo el email
Dim msg As New System.Net.Mail.MailMessage()
msg.To.Add("destinatario@dominio.com")
msg.From = New MailAddress("envia@dominio.com", "Envios", System.Text.Encoding.UTF8)
msg.Subject = "Cámaras en imágenes"
msg.SubjectEncoding = System.Text.Encoding.UTF8
msg.IsBodyHtml = True
msg.Body = "Se adjuntan imágenes..."
msg.BodyEncoding = System.Text.Encoding.UTF8
Dim client As New SmtpClient()
client.Credentials = New System.Net.NetworkCredential("envios@dominio.com", "LoremIpsum")
client.Port = 25
client.Host = "mail.dominio.com"
' Conexión a los DBF de parámetros de las cámaras
Dim dbConexionExitosa As Boolean
Dim ConnectionString As String
ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & xRutaImagenLocal & ";Extended Properties=dBase IV"
Dim dBaseConnection As New System.Data.OleDb.OleDbConnection(ConnectionString)
Try
dBaseConnection.Open()
dbConexionExitosa = True
Catch x As Exception
dbConexionExitosa = False
End Try
If dbConexionExitosa Then
Dim dBaseCommand As New System.Data.OleDb.OleDbCommand("SELECT ... FROM ... WHERE ...", dBaseConnection)
Dim dBaseDataReader As System.Data.OleDb.OleDbDataReader = dBaseCommand.ExecuteReader(CommandBehavior.SequentialAccess)
While dBaseDataReader.Read
Dim nCamNumero As Integer = dBaseDataReader("numero")
Dim xCamNombre As String = dBaseDataReader("nombre").ToString
Dim xURL_Port As String = dBaseDataReader("url_port").ToString
Dim xUser As String = dBaseDataReader("user").ToString
Dim xPass As String = dBaseDataReader("pass").ToString
Dim xImgFinal As String = dBaseDataReader("img_final").ToString
Dim xNombreSuc As String = dBaseDataReader("nombresuc").ToString
xURL = xURL_Port & xImgFinal
xImagenLocal = xRutaImagenLocal & xCarpetaImagenes & xNombreSuc & "_" & xCamNombre & ".jpg"
Dim webClient As New WebClient()
webClient.UseDefaultCredentials = True
webClient.Credentials = New NetworkCredential(xUser, xPass)
ReDim Preserve arrayArchivosParaBorrar(nn)
arrayArchivosParaBorrar(nn) = xImagenLocal
nn = nn + 1
Try
webClient.DownloadFile(xURL, xImagenLocal)
msg.Attachments.Add(New System.Net.Mail.Attachment(xImagenLocal))
Catch ex As Exception
msg.Attachments.Add(New System.Net.Mail.Attachment(xImagenNoImagen))
End Try
webClient.Dispose()
End While
Else
msg.Body = "<strong>No connection to database.</strong>"
End If
client.Send(msg)
Dim zImagenLocal As String
For i = 0 To UBound(arrayArchivosParaBorrar)
zImagenLocal = arrayArchivosParaBorrar(i)
If File.Exists(zImagenLocal) Then
Try
My.Computer.FileSystem.DeleteFile(zImagenLocal)
Response.Write("<p>File deleted: " & zImagenLocal & "</p>")
Catch ex As Exception
' No se pudo borrar el archivo!
Response.Write("<p>I can´t delete this file... " & zImagenLocal & "</p>")
End Try
End If
Next
End Sub
End Class