Watching a text File for Activity


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Watching a text File for Activity

  1. #1
    Join Date
    Feb 2005
    Posts
    46

    Watching a text File for Activity

    Hello,

    I know you can use the FileSystemWatcher to raise events in .NET code when new files come into the foler or get updated or whatnot, but I'm trying to implement something where I can watch a specific file that stays open, and when something is written to it, it raises an event in my code and I can go read from the file. Does anyone know how this could be done?

    Thanks!!

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Isn't the file updated when something gets written to it? If so, can't you use the FileSystemWatcher to raise an event?
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Feb 2005
    Posts
    46
    Yes, but how do I know for sure which file was updated? Wether it was the file I want to look at, or another file in the folder.

  4. #4
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    In the event handler for the FileSystemWatcher, check the last-updated time of the file in which you're interested. If it has been updated within the last n seconds, then process it.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  5. #5
    Join Date
    May 2005
    Posts
    4
    You could also check the FullPath or Name properties of the FileSystemEventArgs you get in the event to see if it matches the name you want.

  6. #6
    Join Date
    Jun 2004
    Posts
    93
    set
    filesystemwatcher.filter = "yourfile.extension"

    and you only get events for the file of interest.

    Darren

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center