Users Online

· Guests Online: 52

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Trap Events from File

C# Program to Trap Events from File

 

 

This C# Program to Trap Events from File. Here the events that happen in the specified locations are trapped.

 

Here is source code of the C# Program to Trap Events from File. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

  1. /*
  2.  * C# Program to Trap Events from File
  3.  */
  4. using System;
  5. using System.IO;
  6. class Test 
  7. {
  8.     static void namechang(object sender, RenamedEventArgs evn) 
  9.     {
  10.         Console.WriteLine("{0} NameChanged to {1}", evn.OldFullPath, evn.FullPath);
  11.     }
  12.     static void changed(object sender, FileSystemEventArgs evn) 
  13.     {
  14.         Console.WriteLine(evn.FullPath + " " + evn.ChangeType);
  15.     }
  16.     static void Main(string[] arg) 
  17.     {
  18.         FileSystemWatcher w = new FileSystemWatcher();
  19.         w.Path = "d:\\srip";
  20.         w.NotifyFilter = NotifyFilters.FileName | NotifyFilters.DirectoryName |
  21.                          NotifyFilters.LastAccess | NotifyFilters.LastWrite;
  22.         w.Filter = "";
  23.         w.Created += new FileSystemEventHandler(changed);
  24.         w.Deleted += new FileSystemEventHandler(changed);
  25.         w.Changed += new FileSystemEventHandler(changed);
  26.         w.Renamed += new RenamedEventHandler(namechang);
  27.         w.EnableRaisingEvents = true;
  28.         Console.WriteLine("Press any key to quit");
  29.         Console.Read();
  30.     }
  31.  }

Here is the output of the C# Program:

Press any key to quit

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.94 seconds
10,844,322 unique visits