1

我正在尝试使用 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 几乎没有帮助。任何人以前遇到过这个或知道我在哪里可以找到更多信息?

4

1 回答 1

1

http://support.microsoft.com/kb/814068

总之:

当 Excel 保存文件时,Excel 会执行以下步骤:

  1. Excel 在您在“另存为”对话框中指定的目标文件夹中创建一个随机命名的临时文件(例如,没有文件扩展名的 Cedd4100)。整个工作簿被写入临时文件。
  2. 如果将更改保存到现有文件,Excel 将删除原始文件。
  3. Excel 重命名临时文件。Excel 为临时文件提供您在“另存为”对话框中指定的文件名(例如 Book1.xls)。
于 2010-02-03T02:39:26.450 回答