![.net filewatcher .net filewatcher](https://www.codeproject.com/KB/files/C__FileWatcher/new_components-r-400.jpg)
Json File to be saved as fw.json in local folder mentioned above. The operating system and FileSystemWatcher object interpret a cut-and-paste action or a move action as a rename action for a folder and its contents. Next Dim zRetVal As String = Console.ReadLine()Įnd Sub Private Sub InvokeMethod( ByVal sender As Object, ByVal e As FileSystemEventArgs)Ĭonsole.WriteLine( " Change in file ", e.FullPath) For Each _folder As Folder In _IntegrationFiles.Folders ' iterate through the configuration and assigning folders to watchĬonsole.WriteLine( " File watch initiated for " + _folder.Name + " : \\" + _folder.IP + " \" + _folder.Folder + " \")ĭim Watcher1 As Watcher = New Watcher( " \\" + _folder.IP + " \" + _folder.Folder, " *.*", mymethod) _IntegrationFiles = JsonConvert.DeserializeObject( Of IntegrationFiles)(IO.File.ReadAllText(DP + " \_bin\_config\_fw.json")) ' Read configuration from json. Public Sub _Fn_StartMultipleFolderWatch() ' Call this Sub to start the watch Dim mymethod As invokeMethodDelegate = New invokeMethodDelegate( AddressOf InvokeMethod)
#.net filewatcher code
Implementation to iterate to multiple folders from Json file stored in \_bin\_config\_fw.jsonĬopy Code Delegate Sub invokeMethodDelegate( ByVal sender As Object, ByVal e As FileSystemEventArgs)ĭim _IntegrationFiles As IntegrationFiles = New IntegrationFiles Public Sub New( ByVal directory As String, ByVal filter As String, ByVal invokeMethod As )įileSystemWatcher.EnableRaisingEvents = True AddHandler fileSystemWatcher.Changed, New FileSystemEventHandler( AddressOf fileSystemWatcher_Changed)Įnd Sub Private Sub fileSystemWatcher_Changed( ByVal sender As Object, ByVal e As FileSystemEventArgs) Public Property ChangeMethod As Įnd Set End Property Private fileSystemWatcher As FileSystemWatcher = New FileSystemWatcher() Public Property Directory As String Public Property Filter As String Private _changeMethod As
![.net filewatcher .net filewatcher](https://img-bbs.csdn.net/upload/202004/23/1587612097_532344.jpg)
New FileSystemEventHandler(fileSystemWatcher_Changed) ģ2: void fileSystemWatcher_Changed( object sender, FileSystemEventArgs e)ģ6: _changeMethod.DynamicInvoke(sender, e) Īnd we can use it to monitor multiple directories as shown below (for this example, I have used a console application and I am only considering the change event):
![.net filewatcher .net filewatcher](https://3.bp.blogspot.com/-uOnjyZdnOxU/UAQkok6BD7I/AAAAAAAAAPw/HBVbrRu15ug/s1600/do.png)
14: FileSystemWatcher fileSystemWatcher = new FileSystemWatcher() ġ6: public Watcher( string directory, string filter, Delegate invokeMethod)Ģ5: fileSystemWatcher.Filter = this.Filter Ģ6: fileSystemWatcher.Path = this.Directory Ģ7: fileSystemWatcher.EnableRaisingEvents = true