Geeks With Blogs


Add to Google

Tim Hibbard CEO for EnGraph software

The FileSystemWatcher is very useful when you need to be notified of changes made to a specific folder. You can raise an event when a new file is created, or deleted and you can also filter by file type and choose if you wish to monitor sub directories. The only problem with the object comes with large file transfers. The created event is raised as soon as the file transfer begins to your watched folder, not when the file has finished transferring. So if you need to move a file or pull data out a file, you will get an error if the file hasn't completely copied yet. In one of our enterprise GPS solutions, we transfer GPS data over VPN and we need to know when the file has fully transferred.

I extended the FileSystemWatcher class and added a new event, ChangeComplete. This event is raised after a new file is completely transferred or is renamed. I accomplished this by adding files from the created event to a queue and then trying to open them exclusively every two seconds. If the open call failed, then the file is not finished transferring. If the call succeeds, I close the file and then I raise the ChangeComplete event. I've posted the code here:

Posted on Friday, September 8, 2006 3:14 PM .NET | Back to top

Comments on this post: Extending the IO.FileSystemWatcher object

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Tim Hibbard | Powered by: