csharp file watcher

Code Example - csharp file watcher

                
                        public MainWindow()
{
    InitializeComponent();

    FileSystemWatcher fsw = new FileSystemWatcher();
    fsw.Filter = "test1.csv";
    fsw.NotifyFilter = NotifyFilters.LastWrite;
    fsw.Path = "z:\\temp\\";
    fsw.Changed += Fsw_Changed;
    fsw.EnableRaisingEvents = true;    
}

private void Fsw_Changed(object sender, FileSystemEventArgs e)
{
    MessageBox.Show(e.FullPath);
}
                    
                
 

how to use file watcher in csharp

                        
                                private void watch()
{
  FileSystemWatcher watcher = new FileSystemWatcher();
  watcher.Path = path;
  watcher.NotifyFilter = NotifyFilters.LastWrite;
  watcher.Filter = "*.*";
  watcher.Changed += new FileSystemEventHandler(OnChanged);
  watcher.EnableRaisingEvents = true;
}