I am attempting to use the VB.Net FileSystemWatcher class to watch a folder for the creation of Excel files. I do get a response when a .xls file is created in the folder, but am having a problem with the below code:
Private Sub AddWatch()
Dim watch As New FileSystemWatcher
AddHandler watch.Changed, AddressOf FileChange
watch.Filter = "*.*"
watch.NotifyFilter = NotifyFilters.LastWrite
watch.Path = "C:\Documents and Settings\my.user\Desktop\testing"
watch.EnableRaisingEvents = True
End Sub
Private Sub FileChange(ByVal obj As Object, ByVal e As System.IO.FileSystemEventArgs)
Debug.Print("changetype is: " & e.ChangeType.ToString & ", path is: " & e.FullPath.ToString)
End Sub
When I create a text file in this folder, I get back the proper filename(“C:\Documents and Settings\my.user\Desktop\testing\foo.txt”). However, when I save an Excel file into the folder, the path is still correct, but the filename is garbage (differs each time even with the same filename, always 8 characters like “C:\Documents and Settings\my.user\Desktop\testing\DE0B5800”.) Can’t find a thing on this searching Google or here, and MSDN as usual is little help. Anyone run across this before or know where I can find more information?
http://support.microsoft.com/kb/814068
In summary: