// Wire events. watcher.Changed += new FileSystemEventHandler(watcher_Changed); watcher.Created += new FileSystemEventHandler(watcher_Created); watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
The Created event will be fired when a file is created for example. And don't reset the fileWatcher.Path = path; everytime. Because you overwrite the current path.
Foreach root you must create an dedicated FileSystemWatcher object!
How to monitor files in different folders using the FileSystemWatcher?
How to monitor files in different folders using the FileSystemWatcher?
JRCJames
P.J. I couldn't thank you more
Ade S. Miller - MSFT
And you resert the Filepath every time in the loop. For each root directory you need a dedicated FileSystemWatcher object.
Recharge
Does anyone happen to have the VB 2005 version of this
I tried to figure it out but I've got the sqiggleez happening everywhere.
ArvindAg
freedfouse
Try:
http://authors.aspalliance.com/aldotnet/examples/translate.aspx
I like it!
chankl78
private ArrayList _watchers = new ArrayList();
protected void WatchRootDirectory( string root )
{
// Create filesystemwatcher and set property values.
FileSystemWatcher watcher = new FileSystemWatcher( root );
watcher.IncludeSubdirectories = true;
watcher.EnableRaisingEvents = true;
watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.FileName | NotifyFilters.DirectoryName;
// Wire events.
watcher.Changed += new FileSystemEventHandler(watcher_Changed);
watcher.Created += new FileSystemEventHandler(watcher_Created);
watcher.Deleted += new FileSystemEventHandler(watcher_Deleted);
// Add to collection.
_watchers.Add( watcher );
}
private void watcher_Changed(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " changed." );
}
private void watcher_Created(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " created." );
}
private void watcher_Deleted(object sender, FileSystemEventArgs e)
{
MessageBox.Show( this, e.FullPath + " deleted." );
}
22fox
SvenK
The Created event will be fired when a file is created for example.
And don't reset the fileWatcher.Path = path; everytime. Because you overwrite the current path.
Foreach root you must create an dedicated FileSystemWatcher object!