Hi, again.
I'm using the filesystemwatcher, but it doesn't seem to be picking up on the created file. Here's my code... What am I missing? The event never happens. I go in and create a txt file manually. I would expect that to trigger the event - shouldn't it? (Note that I'm very new and have never created an event like this). Thanks for the help once again!
Public Sub Main()
Dim strPath As String
maxDate = DateAdd(DateInterval.Year, -2, Now())
strEmail = GetEmailString()
strPath = "c:\temp"
Dim watcher As New FileSystemWatcher()
watcher.Path = strPath
' Watch for changes in creation time only
watcher.NotifyFilter = (NotifyFilters.CreationTime)
' Only watch text files.
watcher.Filter = "*.txt"
' Add event handlers.
AddHandler watcher.Created, AddressOf OnCreated
' Begin watching.
watcher.EnableRaisingEvents = True
' Wait for the user to quit the program.
Console.WriteLine("Press 'q' to quit the Invoice NoFailure Notification.")
While Chr(Console.Read()) <> "q"c
End While
End Sub
' Define the event handler.
Private Sub OnCreated(ByVal source As Object, ByVal e As FileSystemEventArgs)
' Specify what is done when a file is changed, created, or deleted.
Console.WriteLine("File: " & e.FullPath & " " & e.ChangeType)
Dim strNewFile As String = ""
strNewFile = e.FullPath
Dim fi As FileInfo = New FileInfo(strNewFile)
maxDate = fi.CreationTime
CreateFile(maxDate.ToString, "c:\temp\test.txt")
End Sub
Sub CreateFile(ByVal strText As String, ByVal strPath As String)
If File.Exists(strPath) Then
File.Delete(strPath)
End If
'File.Create(strPath)
'File.AppendText(strText)
' Create the file.
Dim fs As FileStream = File.Create(strPath, 1024)
Dim info As Byte() = New UTF8Encoding(True).GetBytes(strText)
' Add some information to the file.
fs.Write(info, 0, info.Length)
fs.Close()
End Sub