我正在尝试使用 VB.Net FileSystemWatcher 类来监视用于创建 Excel 文件的文件夹。在文件夹中创建 .xls 文件时,我确实收到了响应,但是下面的代码有问题:
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
当我在这个文件夹中创建一个文本文件时,我得到了正确的文件名(“C:\Documents and Settings\my.user\Desktop\testing\foo.txt”)。但是,当我将 Excel 文件保存到文件夹中时,路径仍然正确,但文件名是垃圾(即使文件名相同,每次都不同,总是 8 个字符,如 "C:\Documents and Settings\my.user\Desktop \testing\DE0B5800".) 在这个搜索谷歌或这里找不到任何东西,和往常一样 MSDN 几乎没有帮助。任何人以前遇到过这个或知道我在哪里可以找到更多信息?