The FileSystemWatcher class in the System.IO namespace can be used to monitor changes to the file system.
It watches a file or a directory in your system for changes and triggers events when changes occur.In order for the FileSystemWatcher to work, you should specify a directory that needs to be monitored.

The FileSystemWatcher raises the following events when changes occur to a directory that it is monitoring.
Changed: This event is triggered when a file or a directory in the path being monitored is changed
Created: This event is triggered when a file or a directory in the path being monitored is created
Deleted: This event is triggered when a file or a directory in the path being monitored is deleted
Error: This event is triggered there is an error due to changes made in the path being monitored
Renamed: This event is triggered when a file or a directory in the path being monitored is renamed

Creating a simple file system watcher in C#
Let’s create a new console application project in Visual Studio to demonstrate how a typical file system watcher works. Note that a better way to use the FileSystemWatcher class would be by using a Windows Service. You can build a Windows Service that uses the FileSystemWatcher class and sends out notifications as and when changes occur to the path being watched.To read this article in full or to leave a comment, please click here

Leave a Reply