Global variables
public static FileSystemWatcher watcher;
<summary>
Setting the Listening configuration
</summary>
<returns>ture/false</returns>
public static Boolean Setmonitorfile ()
{
Try
{
Watcher = new FileSystemWatcher ();
Watcher.filter = "*.txt";
Watcher.path = "d:\\"; Path
Watcher.notifyfilter = notifyfilters.size; File size Change
File Change Event
Watcher.changed + = new FileSystemEventHandler (watcher_changed);;
File Creation Events
watcher.created + = new FileSystemEventHandler (watcher_created);
File Delete Event
watcher.deleted + = new FileSystemEventHandler (watcher_deleted);
File Rename Event
Watcher.renamed + = new Renamedeventhandler (watcher_renamed);
Setting up a listener subdirectory
Watcher.includesubdirectories = false;
Start listening (this is actually the indication of whether the event is monitored and thrown)
Watcher.enableraisingevents = true;
Watcher. EndInit ();
return true;
}
catch (Exception ex)
{
return false;
}
}
C # Listener File