Hey!

I'm going to make a windows service file watcher program. What it going to happened is that some time during the first day of each month, files are going to be added to a directory on the web server. The files are going to look pretty much like this:
file_1_11.csv
file_2_11.csv
...
file_11_11.csv

So, when the eleventh(ie the last file. it can vary from month to month) file is copied to the directory, I want to start reading the files and add them to a database. I got the reading and the insertion to the database all sorted out, but I'm not really sure about how to start with the file watching. I've read some about on the Internet, and I understand that there might be som problems using the built in FileSystemWatcher when working with multiple files. Anyone got an idea on how to attack the task?

Thanks
Suunker

You could use a FileSystemWatcher, but the frequency that these files are dropped, you could also consider polling once a day, and counting the number of files that you have not seen before (or whatever you need to do).

I haven't used FileSystemWatcher that much, as I would do this task using SSIS personally. I'm going to guess that the problem that you are alluding to might be due to the fact that the watcher will raise an event for each file that comes in, and you will get multiple events firing that you will have to deal with.

Yep, I can see how this could get messy trying to count files, read filenames or whatever - with the frequency of your files being dropped, I would use a polling mechanism in C#, or SSIS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.