程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> C# 文件監視器簡單例子源碼

C# 文件監視器簡單例子源碼

編輯:C#入門知識

   C# 文件監視器簡單例子源碼
   
private void btn_FileWatcher_Click(object sender, EventArgs e)
        {
            FileSystemWatcher k8watcher = new FileSystemWatcher();
            k8watcher.Path = "d:\\K8team";
            k8watcher.IncludeSubdirectories = true;
            k8watcher.EnableRaisingEvents = true;
            k8watcher.SynchronizingObject = this;
            k8watcher.Created += new FileSystemEventHandler(k8fileCreated);
            k8watcher.Changed += new FileSystemEventHandler(k8fileChanged);
            k8watcher.Renamed += new RenamedEventHandler(k8fileRenamed);
            k8watcher.Deleted += new FileSystemEventHandler(k8fileDeleted);
        }

        public void k8fileCreated(object sender, FileSystemEventArgs e)
        {
            string log = string.Format(e.ChangeType + ":{0} --時間:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
            txt_Relust.AppendText(log);
        }

        public void k8fileChanged(object sender, FileSystemEventArgs e)
        {
            string log = string.Format(e.ChangeType + ":{0} --時間:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
            txt_Relust.AppendText(log);
        }

        public void k8fileDeleted(object sender, FileSystemEventArgs e)
        {
            string log = string.Format(e.ChangeType + ":{0} --時間:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
            txt_Relust.AppendText(log);
        }

        public void k8fileRenamed(object sender,FileSystemEventArgs e)
        {
            string log = string.Format(e.ChangeType+":{0} --時間:{1}\r\n\r\n", e.FullPath, DateTime.Now.ToString());
            txt_Relust.AppendText(log);

        }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved