FileSystemWatcher problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've got a FileSystemWatcher set like this:

----CODE SAMPLE-------------
fsw = new FileSystemWatcher(@"D:\Test\");
fsw.NotifyFilter = NotifyFilters.LastWrite;
fsw.IncludeSubdirectories = false;

fsw.Changed += new FileSystemEventHandler(fsw_Changed);
fsw.Created += new FileSystemEventHandler(fsw_Created);

fsw.EnableRaisingEvents = true;
----CODE SAMPLE-------------

The goal is to get a notice when a file is copied to this directory. This
works just fine using ctrl-x, ctrl-v or using drag/drop functionality from
another disk, but not using drag/drop on the same disk (say, for example,
dragging a file from d:\ on the Test directory and thus moving it to d:\test).

What is going wrong?

Thanks in advance,
Brecht
 
If you are using the code in a Windows Service, although it will work fine
the first time but subsequently, it won't because you might have put the code
in the Start method of the service, which executes onluy once. If yes, you
have to put the code in a components timer tick event.

Secondly, modify the path from "D:\test" to just "D:\" and turn on

fsw.IncludeSubdirectories = true;

and,

fsw.EnableRaisingEvents = false; if the subdirectory is any directory other
than the "test" directory. A bit of a roundabout way but it will work.

Thirdly, the event handler(s) statements. If you have placed the
eventhandler(s) in any other member other than the constructor of the class,
it may be causing the problem.

with regards,

J.V.
 
Back
Top