Hey there,

I've written the following code. It works fine for creating, deleting and renaming files. However when I set a file to read only, or modify the file (i.e open it in notepad and change the contents) nothing happens (it doesn't hit the change breakpoint)

I have the following code:

VB.NET Code:
  1. Private fsw As FileSystemWatcher
  2.  
  3.  Public Sub WatchFiles(ByVal tblMappings As DataSet)
  4.         For Each row As DataRow In tblMappings.Tables(0).Rows
  5.             Try
  6.                 fsw = New FileSystemWatcher
  7.                 Dim FolderPath As String = row.Item(2)
  8.                 If Directory.Exists(FolderPath) Then
  9.  
  10.                     fsw.Path = FolderPath
  11.                     fsw.NotifyFilter = IO.NotifyFilters.DirectoryName
  12.                     fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.FileName
  13.                     fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.Attributes
  14.                     fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.LastWrite
  15.                     fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.Size
  16.                     fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.LastAccess
  17.                     fsw.NotifyFilter = NotifyFilters.LastAccess Or NotifyFilters.DirectoryName Or NotifyFilters.FileName Or NotifyFilters.CreationTime
  18.                     fsw.IncludeSubdirectories = False
  19.                     fsw.EnableRaisingEvents = True
  20.  
  21.                     AddHandler fsw.Changed, AddressOf fsw_changed
  22.                     AddHandler fsw.Created, AddressOf fsw_created
  23.                     AddHandler fsw.Renamed, AddressOf fsw_renamed
  24.                     AddHandler fsw.Deleted, AddressOf fsw_deleted
  25.                     fsw.EnableRaisingEvents = True
  26.                 End If
  27.  
  28.             Catch ex As Exception
  29.                 MessageBox.Show(ex.Message)
  30.             End Try
  31.         Next
  32.  
  33.     End Sub
  34.    
  35.  Private Sub fsw_changed(ByVal sender As Object, ByVal e As FileSystemEventArgs)
  36.         Dim db As New DatabaseFunctions
  37.         db.AddToLog(DatabaseFunctions.PendingType.Change, e.FullPath, GetServerFolderFromPCFolder(ftp.GetFolder(e.FullPath), _tblMappings), String.Empty, _strUsername, _strPassword, _strDomain, _strAusername, _tblMappings)
  38.     End Sub

Does anybody have any ideas as to whats going wrong?

Regards,

Adam.