Ok, I have been ignoring this blog for a while now, but now I am back. I finally have some time again. Sorry everyone.
Due to numerous requests for a way to tell the FileSystemWatcher control to wait for a file to finish uploading before it performs an action, I am creating this post. I was actually having the same problem and it took me a while to figure out that this was actually the problem I was having. So here is my fix.
If you have read my previous post on the FileSystemWatcher control, I posted code for a simple service that runs in the background ad copies files from one server to another. Basically, the fix is to add the following few lines of code to the create and change events:
while (!File.Exists(sample.file))
{
//keep looping until the file is unlocked.
}
Basically, when the file is still being uploaded, the file is locked and the Exists function will return false. Once it is done uploading, the program will continue, and it will be able to copy the file to perform actions on the file.
Let me know if you have any problems.
Comments