FileSystemWatcher in C#

Hi all,

Here is the simple description to use FileSystemWatcher in your desktop application by using C#.

Just drag the FileSystemWatcher control in your form from under the Components tab in the toolbox.

And copy the following code in to load event,

private void Form1_Load(object sender, EventArgs e)
{
fileSystemWatcher.Path = flvPath;
fileSystemWatcher.Filter = "*.flv";
fileSystemWatcher.NotifyFilter = NotifyFilters.FileName | NotifyFilters.CreationTime | NotifyFilters.LastWrite;
fileSystemWatcher.EnableRaisingEvents = true;
}

If the file watcher found any newly created file, the following event will rise.

private void fileSystemWatcher_Created(object sender, FileSystemEventArgs e)
{
MessageBox.Show(e.Name + " created in " + e.FullPath);
}


An event is rising when a file deleted.

private void fileSystemWatcher_Deleted(object sender, FileSystemEventArgs e)
{
MessageBox.Show(e.Name + " changed in " + e.FullPath);
}

An event is rising when a file renamed.


private void fileSystemWatcher_Renamed(object sender, RenamedEventArgs e)
{
MessageBox.Show(e.Name + " renamed in " + e.FullPath);
}

That’s it…

...S.VinothkumaR.

1 comment:

honeydear said...

Hi, I had downloaded your source code of "Setting Bluetooth discoverable in Windows Mobile" from code project. Thanks a lot.
However, i am facing the problem in converting the C# source code to VB .NET. Can you please help me?

Thank you.