tags:

views:

21

answers:

2

Hi everyone!

I need to import multiple csv files, compressed in a zipped folder. I am using Visual Studio 2008/SQL server 2005.

I am thinking either create some kind of File upload .net control OR allow users to copy files to a network share, then run some kind of import utility to import data into SQL server.

The tricky part for me is should I write windows service to import files or is there any other cleaner solution.

A: 

Write a Windows service if you want it to be automated.

You could either use a Timer and set it to run the import at a set interval.

Or setup a FileSystemWatcher and look for .csv files in a particular folder, when a new file is created in the directory it is watching, run your method for importing the CSV.

Sounds like you already know how to do the import, so the above are just two suggestions for automating the process.

Setup FileSystemWatcher

FileSystemWatcher csvWatcher = new FileSystemWatcher();
csvWatcher.Path = "C:\Imports"; //Put the Dir to watch here
csvWatcher.Filter = "*.csv";
csvWatcher.EnableRaisingEvents = true;
csvWatcher.Created += new FileSystemEventHandler(csvWatcher_Created);

Event Handler

void csvWatcher_Created(object Sender, FileSystemEventArgs e)
{
//Call Import Method
}
Dan Harris
A: 

If you want the users to copy them to a network share, a windows service is the best way to go. Look at the FileSystemWatcher for a way of detecting when files appear in the folder.

Justin Dearing