★★★送分快来抢★★★:FileSystemWatcher类在asp.net中怎么不能监视文件的变化呢?

解决方案 »

  1.   

    使用方法如下: 在global.asax文件中的Application_Start里添加
    DirWatch dw = new DirWatch();
    dw.Initial();DirWatch类是在app_code文件夹下
    void Watch()
        {
            
            FileSystemWatcher fw = new FileSystemWatcher(dir);
            fw.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastAccess | NotifyFilters.LastWrite;
            
            fw.Created += new FileSystemEventHandler(fw_Created);
            fw.Deleted += new FileSystemEventHandler(fw_Deleted);
            fw.EnableRaisingEvents = true;
        }    void fw_Deleted(object sender, FileSystemEventArgs e)
        {
            throw new Exception("The method or operation is not implemented.");
        }
      

  2.   

    cool99() 说的对,放在Application_Start事件里,WEB服务启动的时候就能开始执行文件状态观察了。不能写在Asp.net的页面事件里,只能放在这个服务器只要启动网站便一直存在的事件中
      

  3.   

    to benq2003(Visual奎#.Net 2005):FileSystemWatcher类在asp.net中怎么不能监视文件的变化呢?
    加了fw.Changed += new FileSystemEventHandler(fw_Changed);也没用
      

  4.   

    to cool99():
    我觉得可以单独写个服务程序
    然后在Application_Start启动这个服务