FileSystemWatcher.Changed fires immediately when Excel 2007 opens XLS file in compatibility mode

Posted by Rick Mogstad on Stack Overflow See other posts from Stack Overflow or by Rick Mogstad
Published on 2010-03-08T18:28:02Z Indexed on 2010/03/08 18:36 UTC
Read the original article Hit count: 888

We use a FileSystemWatcher to monitor documents opened from our Document Management system, and if the user saves the document, we ask if they would also like them updated in our system.

We have a problem with XLS files in Excel 2007 (have not verified that the problem does not exist in 2003, but it only seems to be files that open in compatibility mode in 2007) where the Changed event fires immediately upon opening the file, and then once more upon closing the file, even if nothing has changed or the user chooses not to save upon closing. This same behavior does not exist when opening XLSX files.

I wrote a test app to verify the behavior, which you can find at (http://www.just2guys.net/SOFiles/FSWExcel.zip). In the app, there is one FileSystemWatcher for each NotifyFilter type, so that it is apparent why the Changed event was fired.

Any way you can think of to only prompt the user when the document is actually saved in some way by the user? I can start monitoring the file after Process.Start is called, which allows me to skip the message upon opening the document, but I still get one upon closing the document, even when nothing was changed.

© Stack Overflow or respective owner

Related posts about .NET

Related posts about filesystemwatcher