FileSystemWatcher class allows to get notification on any change in the directory. The notification can be even filtered by changes like rename, delete and all. File types can be specified to the class to allow notification for a particular file types.
- Dim watchFile As New FileSystemWatcher()
- watchFile.Filter = ConfigurationManager.AppSettings.Item(“FileType”)
- watchFile.IncludeSubdirectories = False
- watchFile.Path = ConfigurationManager.AppSettings.Item(“WatcherPath”)
- AddHandler watchFile.Changed, AddressOf FileNotification
- AddHandler watchFile.Renamed, AddressOf FileNotification
- AddHandler watchFile.Deleted, AddressOf FileNotification
- watchFile.EnableRaisingEvents = True
The file watcher is implemented using the WCF Callback function. Whenever any change in the specified directory an event is triggered and a callback function is called. The WCF client program will listen to the callback function and update the control. For sample program the changes are formed as XML string and returned in the callback. When the callback function is called the xml is updated to the rich text control of the forms client.
- Public Class NotificationImpl
- Implements CallbackClient.ServiceClient.ICallbackServiceCallback
- Private rtx As RichTextBox
- Public Sub New(ByVal MyRtx As RichTextBox)
- rtx = MyRtx
- End Sub
- Public Sub Callback(ByVal OutXml As String) Implements ServiceClient.ICallbackServiceCallback.Callback
- rtx.AppendText(“——-START: “ & DateTime.Now.ToString(“dd/MMM/yyyy hh:mm:ss”) & “———-“ & Chr(13))
- rtx.AppendText(OutXml)
- rtx.AppendText(Chr(13) & “————-END ————–“ & Chr(13))
- End Sub
- End Class
The WCF service is implemented using the NetTcp binding. The attached file contains the WCF service library and the Console Host for the service. The second attachment contains the form client to get the notification. The samples are in VB code
Download the Source code from below links…
Could you please update the links for download it’s not available. I am trying the same thing so need the code piece.
can you please share the code, your download is not working