Multimobile Development: Building Applications for any Smartphone
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...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
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...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
 
System.Console
System.IO.FileSystemEventArgs
System.IO.FileSystemEventHandler
System.IO.FileSystemWatcher
System.IO.NotifyFilters
System.IO.RenamedEventArgs
System.IO.RenamedEventHandler




Multimobile Development: Building Applications for any Smartphone
Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
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