Filesystemwatcher用于文件打开通知

时间:2014-01-15 12:19:15

标签: c# asp.net

请帮助我计算用户在filesystemwatcher的帮助下打开文件(.txt或.pdf)的次数。

甚至在将NotifyFilter-property设置为LastAccess并捕获Changed-event之后。像这样:

FileSystemWatcher lWatcher = new FileSystemWatcher(@"C:\Documents and Settings\User\Desktop", "myfile.txt");    
lWatcher.NotifyFilter = NotifyFilters.LastAccess;    
lWatcher.Changed += new FileSystemEventHandler(HandlerWatcherChanged);    

void HandlerWatcherChanged(object sender, FileSystemEventArgs e)
{
   // file has been accessed
} 

如有必要,我已启用上次访问时间更新。 我仍然无法得到它。

1 个答案:

答案 0 :(得分:0)

也许您的问题与此相关:

filesystemwatcherchanged-event-does-it-fire-when-a-file-is-accessed

修改

如果没有尝试以下代码:

FileSystemWatcher lWatcher = new FileSystemWatcher(@"C:\Documents and Settings\User\Desktop", "*.txt");    
lWatcher.NotifyFilter = NotifyFilters.LastAccess;    
lWatcher.EnableRaisingEvents = true;
lWatcher.Changed += new FileSystemEventHandler(HandlerWatcherChanged);    

void HandlerWatcherChanged(object sender, FileSystemEventArgs e)
{
   if (e.FullPath.Contains("mfile.txt")) 
         return; //do work here
}