I am a newbie with vb.net and cannot find a solution. I am trying to send an internal email whenever a new file is created in a subfolder. I can successfully monitor and send an email, but can't figure out how to include a UNC path that user can simply click on to open the newly created file. I am open to using SMTP or HTML to make this happen. The line I am struggling with is the mail.Body = line.
Imports System.IO
Imports System.Diagnostics
Imports System.Net.Mail
Public Class Form1
Public watchfolder As FileSystemWatcher ' public variable
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_start.Click
watchfolder = New System.IO.FileSystemWatche
r()
watchfolder.Path = "c:\scanfolders" ' path to monitor
watchfolder.Filter = "*.pdf"
watchfolder.IncludeSubdire
ctories = True
'add filter to montor for filename
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
' add the handler to for the event
AddHandler watchfolder.Created, AddressOf logchange
watchfolder.EnableRaisingE
vents = True
End Sub
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventA
rgs)
Dim EmailAddress, PDFpath, PDFname As String
Dim mail As New MailMessage()
PDFpath = e.Name
txt_folderactivity.Text &= "PDFpath: " & PDFpath & vbCrLf
EmailAddress = Microsoft.VisualBasic.Left
(PDFpath, ((InStr(PDFpath, "\")) - 1)) & "@mycompany.com"
PDFname = Mid(PDFpath, (InStr(PDFpath, "\") + 1), (Len(PDFpath) - (InStr(PDFpath, "\"))))
'********** Send email as SMTP
'set the addresses
mail.From = New MailAddress("ScanMonitor@m
ycompany.c
om")
mail.To.Add(EmailAddress)
'set the content
mail.Subject = "You have a new scanned file"
mail.Body = "Click the link to view your document: \\wbprint\" & PDFpath
'send the message
Dim smtp As New SmtpClient("mail.mycompany
.com")
smtp.Send(mail)
'*************************
**********
**********
**********
**********
******
End Sub
End Class
Start Free Trial