Is there any way to determine if a text file is currently open in a text editor? Or better yet, is there a way to trigger an event when a text file is opened (from any program)?
Using the FileSystemWatcher component you can detect Changed, Created, Deleted, and Renamed events statically.
If you want to detect Last Access you need to manually set the NotifyFilter to include LastAccess.
I think I'll make a Timer that checks the last modified time of the file.... and when the program starts, it'll get the last modified time.
When most editors have a file open they typically follow a set strategy:
1. Open File
2.Read entire contents into buffer
3.Close File
Then your program runs. Since the file is already closed, any attempts to open it will of course succeed. Using a FileSystemWatcher
this can be detected if a file is open or closed. However, you will not be able to detect if the file has been open prior to your program running.