I have the following sub:
Private Sub Watcher_Changed(ByVal sender As System.Object, ByVal e As FileSystemEventArgs)
If Path.GetExtension(e.Name) = \".
I created a service to upload files dumped to an FTP folder a couple years ago and here's some things I did that should help you get over your problem:
This seemed to work out for me and that service ran reliably uploading files for months until I left that job.
I had the same problem today while trying to automatically reload a configuration file on change. I ended up computing an MD5 hash of the file to figure out if the file had actually changed and only reloading if the hash was different. This was the only definitive way I could filter out duplicates.
I briefly thought about using a timer mechanism to filter out change notifications but felt, like pete-m, but I felt it was too unclean a solution.
I tried watching only for LastWrite time changes but that didn't work. I was still getting duplicate notifications.
One thing to note is that accessing the file can change one of the file properties, like "accessed time" or something. That can then fire off another event if you don't have the notification filters setup right.
I ran into the exact situation before, and ended up implementing a timer mechanism to wait for the file to "settle", or for write events to stop coming in for x amount of time.
A bit kludgy, but it worked.
I had this same issue, I was saving a file that was uploaded through code and deleting and creating would fire twice each time. All I had to check was that the File was there before doing my processing.
private void fsw_Created(object sender, FileSystemEventArgs e)
{
if (File.Exists(e.FullPath))
{
//process the file here
}
}
we had a similar situation; however the system that wrote the file in batches used a temp name, and changed it to the "real" name when it was done. Can your ftp client do something similar? If it can, then you can check the new filename and check it by extension or a prefix; if its not the expected final filename format then you can ignore it.