I have a problem with the FileSystemWatcher() Class. It works flawlessly when I’m monitoring a local file on my harddrive. When I change to a mapped UNC, it does not fire anymore. The UNC is mapped to a local drive (X:), with the NET USE command where the user and password are supplied, this is done in a batch file at startup. Anyone that knows why this doesn’t work? I have checked the paths, all of them are correct, so the problem should be related to something else…
fw = new FileSystemWatcher();
fw.Path = fileInfoPath;
fw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fw.Filter = fileInfoName;
fw.Changed += new FileSystemEventHandler(FileOnChanged);
fw.Created += new FileSystemEventHandler(FileOnChanged);
Help appreciated! 🙂
My solution to the problem was to leave the FileSystemWatcher() and create my own little watcher. It’s very simple, but the only thing I wanted to watch was when the file was rewritten and then perform some action.
This is basically what I do (removed try/catch and some invoking of other threads):