private void startActivityMonitoring(string sPath)
{
if (sPath.Length < 3)
{
MessageBox.Show("You have to enter a folder to monitor.",
"Hey..!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
abortAcitivityMonitoring();
}
else
{
// This is the path we want to monitor
_watchFolder.Path = sPath;
// Make sure you use the OR on each Filter because we need to monitor
// all of those activities
_watchFolder.NotifyFilter = System.IO.NotifyFilters.DirectoryName;
_watchFolder.NotifyFilter = _watchFolder.NotifyFilter | System.IO.NotifyFilters.FileName;
_watchFolder.NotifyFilter = _watchFolder.NotifyFilter | System.IO.NotifyFilters.Attributes;
// Now hook the triggers(events) to our handler (eventRaised)
_watchFolder.Changed += new FileSystemEventHandler(eventRaised);
_watchFolder.Created += new FileSystemEventHandler(eventRaised);
_watchFolder.Deleted += new FileSystemEventHandler(eventRaised);
// Occurs when a file or directory is renamed in the specific path
_watchFolder.Renamed += new System.IO.RenamedEventHandler(eventRenameRaised);
// And at last.. We connect our EventHandles to the system API (that is all
// wrapped up in System.IO)
try
{
_watchFolder.EnableRaisingEvents = true;
}
catch (ArgumentException)
{
abortAcitivityMonitoring();
}
}
}
403.5 KB, 下载次数: 256, 下载积分: 金钱 -1
再给大家提供一个文件监控的例子
欢迎光临 CSkin博客 (http://bbs.cskin.net/) | Powered by Discuz! X3.2 |