Search
Module:
Directory

   Desktop Functions:

   Smart Device Functions:


Show Recent Changes
Subscribe (RSS)
Misc. Pages
Comments
FAQ
Helpful Tools
Playground
Suggested Reading
Website TODO List
Download Visual Studio Add-In

FileSystemWatcher (shell32)
 
.
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.

Please edit this page!

Do you have...

  • helpful tips or sample code to share for using this API in managed code?
  • corrections to the existing content?
  • variations of the signature you want to share?
  • additional languages you want to include?

Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).

 
Access PInvoke.net directly from VS:
Terms of Use
Edit This Page
Find References
Show Printable Version
Revisions