1
  • My requirement

I am creating one desktop application , I need a network path file information which raname and create ,for that I use FileSystemWatcher it's provide Created,Renamed,changes and deleted event

  • My problem

FileSystemWatcher rename event not firing for subdirectory network path, I already set watcher.IncludeSubdirectories = true, but it not work for rename

public void Setup() {

    var watcher = new FileSystemWatcher{
        Path = "My network path",
        NotifyFilter = NotifyFilters.FileName | NotifyFilters.Attributes | NotifyFilters.LastWrite | NotifyFilters.Security, Filter = "*"
    };

    watcher.Created += OnCreated;
    watcher.Renamed += OnRenamed;
    // uncomment out line below to add the error handler 
    watcher.Error += OnError; 
    watcher.IncludeSubdirectories = true;
    watcher.EnableRaisingEvents = true;
}

public static void OnRenamed(object source, RenamedEventArgs e)
{           
    try
    {                       
        MessageBox.Show("Raname call");
    }
    catch (Exception Ex)
    {
        errorLog(Ex);
    }
}           

public static void OnCreated(object source, FileSystemEventArgs e)
{
    try
    {
        MessageBox.Show("OnCreated call");
    }
    catch (Exception Ex)
    {
         errorLog(Ex);
    }
}
apr
  • 11
  • 2
  • Other people have had similar issues: https://stackoverflow.com/questions/11219373/filesystemwatcher-to-watch-unc-path, https://stackoverflow.com/questions/960318/filesystemwatcher-fails-to-access-network-drive. Do either of these apply to you? – satnhak Jun 07 '17 at 05:38
  • Do not use MessageBox in events, specially filesystemwatchers, I would recommend plain Console.WriteLine("bla bla"). – Raj Jun 07 '17 at 08:40

0 Answers0