FileSystemWatcher (shell32)
Last changed: -188.129.131.160

.
Summary
TODO - a short description

C# Signature:

[DllImport("shell32.dll", SetLastError=true)]
static extern TODO FileSystemWatcher(TODO);

VB Signature:

Declare Function FileSystemWatcher Lib "shell32.dll" (TODO) As TODO

User-Defined Types:

None.

Alternative Managed API:

Do you know one? Please contribute it!

Notes:

None.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Documentation

Drag FileSystemWatcher control in your form from toolbox and add the events for created,deletion and renaming.

Ex
-

#region Designer view

this.fileSystemWatcher.EnableRaisingEvents = true;

this.fileSystemWatcher.IncludeSubdirectories = true;

this.fileSystemWatcher.SynchronizingObject = this;

this.fileSystemWatcher.Created += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Created);

this.fileSystemWatcher.Deleted += new System.IO.FileSystemEventHandler(this.fileSystemWatcher_Deleted);

this.fileSystemWatcher.Renamed += new System.IO.RenamedEventHandler(this.fileSystemWatcher_Renamed);

public System.IO.FileSystemWatcher fileSystemWatcher;

#endregion

Create three bool variables to set true or false :-

#region Properties

private bool _fileDeleted = false;

private bool _fileRenamed = false;

private bool _fileCreated = false;

public bool FileDeleted

{

set

{

_fileDeleted = value;

}

get

{

return _fileDeleted;

}

}

public bool FileRenamed

{

set

{

_fileRenamed = value;

}

get

{

return _fileRenamed;

}

}

pblic bool FileCreated

{

set

{

_fileCreated = value;

}

get

{

return _fileCreated;

}

}

#endregion

#region EventHandlers

private void fileSystemWatcher_Renamed(object sender, RenamedEventArgs e)

{

_fileRenamed = true;

MessageBox.Show(e.Name " Renamed in " e.FullPath);

}

private void fileSystemWatcher_Deleted(object sender, FileSystemEventArgs e)

{

_fileDeleted = true;

MessageBox.Show(e.Name " Deleted in " e.FullPath);

}

private void fileSystemWatcher_Created(object sender, FileSystemEventArgs e)

{

_fileCreated = true;

MessageBox.Show(e.Name " created in " e.FullPath);

}

#endregion

By this property if you want to check file has been removed ,deleted from physical path then this will be true and you can check like if you have a tree view and you dont want to repopulate your tree view then use filesystemwatcher and repopulate the tree only when files have been changed,delete or rename. or you can throw a messagebox like above.