FileSystemWatcher not firing changed event

  • Thread starter Thread starter Tony
  • Start date Start date
T

Tony

I have setup a FileSystemWatcher to fire an event when the specified file is
modified.
But the event never fires for some reason and the file is being modified.

I have pasted the setup code below. I must be doing something wrong (I have
verified the file names and path as being correct).

Tony

m_oFileSystemWatcher = new
FileSystemWatcher();
m_oFileSystemWatcher.NotifyFilter =
NotifyFilters.LastWrite;
m_oFileSystemWatcher.Path =
Path.GetDirectoryName(sLocalFilename);
m_oFileSystemWatcher.Filter =
Path.GetFileName(sLocalFilename);
m_oFileSystemWatcher.Changed += new
FileSystemEventHandler(OnFileSystemWatcher_Changed);
m_oFileSystemWatcher.EnableRaisingEvents = true;


private void OnFileSystemWatcher_Changed(object sender,
FileSystemEventArgs e)
{
m_bFileModified = true;
}
 
Perhaps the path is the problem. Are you specifying a "fully rooted" path in
sLocalFileName, as in "driveletter:\blah-blah"? If not, you may not be
setting the watcher on the directory you think you are.

David
 
Back
Top