Topaz Filer - Email filing software
FileSystemWatcher
Messages   Related Types
This message was discovered on microsoft.public.dotnet.distributed_apps.


Jaco Jordaan
How must I set the FileSystemWatcher in VB.Net up to watch
for the creation of new folders in a specified folder. I
do get it right to watch for new files created, but when a
folder is created of copied, the watcher does nothing.
Please help.
Reply to this message...
Vote that this is a GOOD answer...
 
New BootFX DBGet build available
Twitter and Snow… simple #uksnow
 
    
Dale Woodford [MS]
I just took the sample code from the FileSystemWatcher class and modified it
a bit.
Here's my code, and it works even when directories are created, etc. Sorry
that its
C# and not VB.NET:

using System;
using System.IO;

public class Watcher
{
public static void Main()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"c:\dale";
watcher.NotifyFilter = NotifyFilters.Attributes |
NotifyFilters.CreationTime | NotifyFilters.DirectoryName |
NotifyFilters.FileName | NotifyFilters.LastAccess | NotifyFilters.LastWrite
| NotifyFilters.Security | NotifyFilters.Size;
watcher.Filter = "";

watcher.Changed += new FileSystemEventHandler(OnChanged);
watcher.Created += new FileSystemEventHandler(OnChanged);
watcher.Deleted += new FileSystemEventHandler(OnChanged);
watcher.Renamed += new RenamedEventHandler(OnRenamed);

watcher.EnableRaisingEvents = true;

Console.WriteLine("Press \'q\' to quit the sample.");
while(Console.Read()!='q');
}

public static void OnChanged(object source, FileSystemEventArgs e)
{
Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType);
}

public static void OnRenamed(object source, RenamedEventArgs e)
{
Console.WriteLine("File: {0} renamed to {1}", e.OldFullPath, e.FullPath);
}
}

Dale

"Jaco Jordaan" <Click here to reveal e-mail address> wrote in message
news:86d401c2648a$15f30df0$3aef2ecf@TKMSFTNGXA09...
[Original message clipped]

Reply to this message...
Vote that this is a GOOD answer...
 
Windows 7 compatible tool for mounting ISO images
Introduction to BootFX’s Object Relational Mapping Functionality article now live on CodeProject
 
 
System.Console
System.IO.FileSystemEventArgs
System.IO.FileSystemEventHandler
System.IO.FileSystemWatcher
System.IO.NotifyFilters
System.IO.RenamedEventArgs
System.IO.RenamedEventHandler




Ad
BootFX
Reliable and powerful .NET application framework.
Looking to invest in a major software project? Technical and commercial advice available here.
Other Helpful Sites
MBR 247
Topaz Filer
SharePoint Email Filing
Software Advisory Services
 
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734