I have a folder that contains multiple word documents. I need to monitor this folder for any changes in these word documents. I am facing the following problems:
FileSystemWatcher
never reports the exact name of file being changed. For example for file abc.doc, it reports "~$abc.doc is changed" on first save.- For all subsequent saves to that file,
OnChanged
event in the following code is not called. When I changed the filter towatcher.Filter = "*.*"
, I found that for subsequent saves, it reports "~WRL0001.tmp is changed".
So the bottom line is that I never know the exact name of the file changed.
I am using the following code
public static void Main()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\Users\Administrator\Documents\"; //"
watcher.NotifyFilter = NotifyFilters.Size;
watcher.Filter = "*.doc";
watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press \'q\' to quit the sample.");
while (Console.Read() != 'q') ;
}
private static void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}