-
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!!
-
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!
-
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.
-
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!
-
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.
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks