I'm using FileSystemWatcher
class to detect new files created in a directory. I'm creating txt and zip files. It's detects perfectly txt files but not the same with zip file. I know if anyone has worked with that and your experience.
Here is my code:
public void CreateWatcher(String path)
{
//Create a new FileSystemWatcher.
FileSystemWatcher watcher = new FileSystemWatcher(path);
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
Thread.Sleep(2000);
//Set the filter to all type of files
watcher.Filter = "*.zip";
//Subscribe to the Created event.
watcher.Created += new FileSystemEventHandler(watcher_FileCreated);
//Enable the FileSystemWatcher events.
watcher.EnableRaisingEvents = true;
}
private void watcher_FileCreated(object sender, FileSystemEventArgs e)
{
logger.InfoFormat("New zip file created -> " + e.Name);
}
Thanks!