Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. System.IO.FileSystemWatcher problem

System.IO.FileSystemWatcher problem

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netsysadminxmlhelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    proach
    wrote on last edited by
    #1

    Hello there, I need to monitor changes made to a certain file from ASP.NET website application. I decided to accomplish this using System.IO.FileSystemWatcher. Currently I am having the following problems 1. I can't make my watcher monitor a single file not just the whole folder content. 2. Even if I try the whole-folder-monitoring scenario it turns out that the Change event fires 5 times instead of 1. Any magic behind this number? Here's the source code inside my Global.asax file. Commented lines include adjustments I tried to enable monitoring specific file. 1 void Application_Start(object sender, EventArgs e) 2 { 3 // Code that runs on application startup 4 5 6 7 System.IO.FileSystemWatcher __file_watcher = new System.IO.FileSystemWatcher(); 8 Application.Add("AdConfigurationWatcher",__file_watcher); 9 __file_watcher.Path = Server.MapPath("~/"); 10 __file_watcher.IncludeSubdirectories = false; 11 __file_watcher.NotifyFilter = System.IO.NotifyFilters.LastWrite; 12 //__file_watcher.Filter = "myconfig.xml"; 13 14 15 __file_watcher.Changed += new System.IO.FileSystemEventHandler(__file_watcher_Changed); 16 17 __file_watcher.EnableRaisingEvents = true; 18 } 19 20 void __file_watcher_Changed(object sender, System.IO.FileSystemEventArgs e) 21 { 22 //do whatever.... this is just for tracing 23 System.IO.WatcherChangeTypes c = e.ChangeType; 24 } 25 26 void Application_End(object sender, EventArgs e) 27 { 28 // Code that runs on application shutdown 29 System.IO.FileSystemWatcher __file_watcher = Application["AdConfigurationWatcher"] as System.IO.FileSystemWatcher; 30 Application.Remove("AdConfigurationWatcher"); 31 __file_watcher.Dispose(); 32 }

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups