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:
Private fsw As FileSystemWatcher Public Sub WatchFiles(ByVal tblMappings As DataSet) For Each row As DataRow In tblMappings.Tables(0).Rows Try fsw = New FileSystemWatcher Dim FolderPath As String = row.Item(2) If Directory.Exists(FolderPath) Then fsw.Path = FolderPath fsw.NotifyFilter = IO.NotifyFilters.DirectoryName fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.FileName fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.Attributes fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.LastWrite fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.Size fsw.NotifyFilter = fsw.NotifyFilter Or IO.NotifyFilters.LastAccess fsw.NotifyFilter = NotifyFilters.LastAccess Or NotifyFilters.DirectoryName Or NotifyFilters.FileName Or NotifyFilters.CreationTime fsw.IncludeSubdirectories = False fsw.EnableRaisingEvents = True AddHandler fsw.Changed, AddressOf fsw_changed AddHandler fsw.Created, AddressOf fsw_created AddHandler fsw.Renamed, AddressOf fsw_renamed AddHandler fsw.Deleted, AddressOf fsw_deleted fsw.EnableRaisingEvents = True End If Catch ex As Exception MessageBox.Show(ex.Message) End Try Next End Sub Private Sub fsw_changed(ByVal sender As Object, ByVal e As FileSystemEventArgs) Dim db As New DatabaseFunctions db.AddToLog(DatabaseFunctions.PendingType.Change, e.FullPath, GetServerFolderFromPCFolder(ftp.GetFolder(e.FullPath), _tblMappings), String.Empty, _strUsername, _strPassword, _strDomain, _strAusername, _tblMappings) End Sub
Does anybody have any ideas as to whats going wrong?
Regards,
Adam.




Reply With Quote