Watch for a file to exist...

SteveoAtilla

Regular
Joined
Dec 22, 2004
Messages
80
Location
The Frozen Tundra
Hello all!

I have an ASP page with VB.NET codebehind pages that needs to watch for a specific file to exist in a specific locaiton on the web server.

Here is the sequence of events:
  • The user causes a file to be created on the server
  • Software on the server will then pick up that text file and create a PDF from it (PlanetPress software - nice stuff)
  • The PDF is written to a different folder in the website
What I need to do is, after the text file is created, I need to watch the output folder for a specific file name. I obviously can't user a timer, so how do I watch a folder for a file? I'd hate to simply loop. What a waste of resource....

Thanks,

Kahuna
 
kahlua001 said:
Do you have control over your PDF software, perhaps upon successfuly creation of the PDF file, raise an event or write to a db.
I don't know about raising an event, but even if it were to write to a DB (the majority of this website interacts with a large SQL database), I would still need to watch that, wouldn't I?
 
marble_eater said:
Would it be possible to use the System.IO.FileSystemWatcher class?
I'm playing with that right now, but it seems to be acting the same as the Timer. As soon as the page loads, there is no longer a connection to the server, so it never sees the file being created.

Is the FileSystemWatcher valid in this context?
 
You can't use it in an ASP.NET page. The web is stateless. The instances of "code behind" classes are constructed and then destructed almost immediately. Furthermore there are no persistently running processes in the web application itself. The best solution to your problem would be to use the FileSystemWatcher in a Windows Service application.
 
Back
Top