Dillon More

Dillon More

  • NA
  • 6
  • 0

How to use the FileSystemWatcher class in .Net to monitor directories on a Server

Nov 8 2005 11:55 PM

I have created a class that uses the FileSystemWatcher class to track and monitor the activity that is happening on the path specified by the user 

FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = "C:\ Programfiles";
watcher.Filter = "*.txt";

watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created +=
new FileSystemEventHandler(OnChanged);
watcher.Deleted +=
new FileSystemEventHandl(OnChanged);
watcher.Renamed +=
new RenamedEventHandler(OnRenamed)watcher.EnableRaisingEvents = true;

Now this does the job it's supposed to do, however now I'm supposed to implement the same kind of functionality for servers in a web farm environment and be able to monitor, for instance if some one is adding some new files to the server, or deleting existing files etc.  Ofcourse for security reasons my program should also have a login of some sort or else the server won't let you get in them (my app needs to be authenticated first). 

I did some research, and it turned out some folks have written windows services for this kind of work, but I'm hoping that there has to be some easier mechanism within the .Net framework that will enable me to do so. Your thoughts on this are welcome.
THanks