Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello every one..
i use FileSystemWatcher for watch on File System. it can watch on particular folder or drive.

But i want it on whole file system means it should watch on all drive.

Any idea about this ?
Posted

SQL
public FileSystemWatcher fsw;

     public void StartMonitoring()
     {

          //Get all Drives of Computer
           DriveInfo[] dinfo = DriveInfo.GetDrives();
          //Loop Through All The Drives
          foreach (DriveInfo d in dinfo)
          {
             try
             {

                 fsw = new FileSystemWatcher(d.RootDirectory.ToString());
                 fsw.EnableRaisingEvents = true;
                 fsw.IncludeSubdirectories = true;
                 fsw.Renamed += new RenamedEventHandler(FileRenamed);
                 fsw.Created += new FileSystemEventHandler(FileCreated);
                 fsw.Deleted += new FileSystemEventHandler(FileDeleted);
             }
             catch
             {
             }
         }
     }
     public void FileRenamed(Object Sender, RenamedEventArgs e)
     {
        messagebox.show( e.FullPath, "Renamed");
     }
     public void FileCreated(Object Sender, FileSystemEventArgs e)
     {

          messagebox.show( e.FullPath, "Created");
     }
     public void FileDeleted(Object Sender, FileSystemEventArgs e)
     {
           messagebox.show( e.FullPath, "Deleted");
     }
     public void StopMonitoring()
     {
          fsw.Dispose();
     }
 
Share this answer
 
Comments
[no name] 14-Mar-13 2:26am    
Thank you
Nelek 15-Mar-13 12:57pm    
In addition to other messages you are receiving... This is exactly the correct way to do it :)
Here is the idea: you are right. You would have to watch on all drives. It the case closed? :-)

—SA
 
Share this answer
 
Comments
[no name] 14-Mar-13 2:25am    
yes case closed :-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900