Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.IO;
- // Create a new FileSystemWatcher object and specify the folder to monitor.
- FileSystemWatcher watcher = new FileSystemWatcher("C:\\FolderToMonitor");
- // Set the event handlers for the Created and Error events.
- watcher.Created += OnCreated;
- watcher.Error += OnError;
- // Start watching the folder for changes.
- watcher.EnableRaisingEvents = true;
- // This method will be called when a new file is created in the folder.
- private static void OnCreated(object source, FileSystemEventArgs e)
- {
- // Print a message to the console.
- Console.WriteLine("A new file was created: " + e.FullPath);
- }
- // This method will be called if there is an error while watching the folder.
- private static void OnError(object source, ErrorEventArgs e)
- {
- // Print a message to the console.
- Console.WriteLine("An error occurred: " + e.GetException().Message);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement