title: FileSystemWatcher used to watch for folder/file open
body: <p>I have browsed around but cannot find any information on what I am seeking, if there is another post that already goes over this then I apologize.</p>
  
  <p>I am seeking help with code that will monitor a specific folder for when the folder is opened by another person or when a file under said folder is opened. At this point I can see when a user opens and modifies any files but if they just open the file to view it, it does not throw an event even when I add LastAccessed. Any information or help would be appreciated.</p>
  
  <p>Folder name is C:\Junk</p>
  
  <p>Code in C# 4.0:</p>
  
  <pre><code>    [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
      public static void Run()
      {
  
  
          FileSystemWatcher watcher = new FileSystemWatcher();
          watcher.Path = @"C:\";
          watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
             | NotifyFilters.FileName | NotifyFilters.DirectoryName;
          watcher.Filter = "junk";
  
          // Add event handlers.
          watcher.Changed += new FileSystemEventHandler(OnChanged);
          watcher.Created += new FileSystemEventHandler(OnChanged);
          watcher.Deleted += new FileSystemEventHandler(OnChanged);
          watcher.Renamed += new RenamedEventHandler(OnRenamed);
          watcher.IncludeSubdirectories = true;
          watcher.EnableRaisingEvents = true;
  
          // Wait for the user to quit the program.
          Console.WriteLine("Press \'q\' to quit the sample.");
          while (Console.Read() != 'q') ;
      }
  
      // Define the event handlers. 
      private static void OnChanged(object source, FileSystemEventArgs e)
      {
          // Specify what is done when a file is changed, created, or deleted.
          Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
      }
  
      private static void OnRenamed(object source, RenamedEventArgs e)
      {
          // Specify what is done when a file is renamed.
          Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
      }
  </code></pre>