vb.net 文件监视返回不正确的文件名
我正在尝试使用 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"。)在 Google 或此处搜索中找不到任何内容,而 MSDN 像往常一样没什么帮助。有人以前遇到过这个或者知道我在哪里可以找到更多信息吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://support.microsoft.com/kb/814068
总之:
http://support.microsoft.com/kb/814068
In summary: