I recently wrote, tested and deployed a .NET 2.0 Windows service to import files into MOSS 2007 sites and document libraries. This service watches a file share (using the FileSystemWatcher class) on another server and moves the file into a MOSS 2007 document library. Here are the salient features:
1. Watches the file share and all folders under that share. Picks up the files as they are created/changed on this share and imports them into MOSS 2007. Deletes the files from the file system after the import. The users are responsible for ensuring that the
2. Accounts for the long copy operations, when the file may not have finished copying when the service goes to pick it up. The way to do that is to open the file in FileShare.None mode and catch the appropriate exception. Wait for a given period of time (few seconds) and retry. Do this the appropriate number of times based on the requirements.
3. Does a clean sweep of the system everytime the service starts to account for the files that it might have missed since the last time it was stopped.
4. Logs the files published/errors to the event log. This helps to track the health of the service - understand what is going right/wrong.
A few things to keep in mind:
1. In the installer class, do not hardcode the password of the account under which the service will run. Do not even read the credentials from a config file. I asked our production environment admins to run the service under a moss service account with enough privileges.
2. Do not do an infinite loop on the number of retries when you cannot get exclusive access to the file. If somebody opens the file and goes home for the day, your service is going to be spinning its wheels trying to get access to that file all night.
3. Review the business case for this requirement. If all that is required is to index these files, you could use MOSS Search to index file shares pretty easily. Also review the business users understand the capabilities of your service, so they dont tax it by creating bogus directories and putting thousands of files in them.
All in all, this service really helps the business because they can automatically import thousands of files into MOSS just by copying them into a file share. I cannot publish the code because the company "owns" that, but hit me up if you need help/advice on how to do this and Ill be glad to guide you.