Advertisement
igoro1975texts

Untitled

Dec 8th, 2022 (edited)
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | Source Code | 0 0
  1. using System.IO;
  2.  
  3. // Create a new FileSystemWatcher object and specify the folder to monitor.
  4. FileSystemWatcher watcher = new FileSystemWatcher("C:\\FolderToMonitor");
  5.  
  6. // Set the event handlers for the Created and Error events.
  7. watcher.Created += OnCreated;
  8. watcher.Error += OnError;
  9.  
  10. // Start watching the folder for changes.
  11. watcher.EnableRaisingEvents = true;
  12.  
  13. // This method will be called when a new file is created in the folder.
  14. private static void OnCreated(object source, FileSystemEventArgs e)
  15. {
  16.     // Print a message to the console.
  17.     Console.WriteLine("A new file was created: " + e.FullPath);
  18. }
  19.  
  20. // This method will be called if there is an error while watching the folder.
  21. private static void OnError(object source, ErrorEventArgs e)
  22. {
  23.     // Print a message to the console.
  24.     Console.WriteLine("An error occurred: " + e.GetException().Message);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement