Click here to Skip to main content
15,919,479 members
Please Sign up or sign in to vote.
2.60/5 (5 votes)
See more:
Hi,

I need C# code to read files in excel format that are already there in a folder and also the files that arrive in the folder and insert the data into a table in the database.The files are delimited by "|".

Any Help will be highly appreciated..... :)
Posted

You just need to keep track whether file is already read into DB or not.

For this purpose you need do :--



1. first create a column(field) to your table to hold the file name which are already read
probably you already have such field.

2. Whenever you copy a file to DB first check if it is not already in the table

if yes
     then do nothing just go next in the loop

if not
     put the absolute path of file into DB
     copy the file into DB in your own way.
 
Share this answer
 
v4
Here is an example for FileSystemWatcher
C#: Application to Watch a File or Directory using FileSystem Watcher[^]

Two excellent libraries for dealing with Excel:
Excel Data Reader - Read Excel files in .NET[^]

EPPlus[^]

It will hopefully et you started ...

Regards
Espen Harlinn
 
Share this answer
 
Comments
fjdiewornncalwe 13-Jan-11 10:23am    
+5. Great answer.
wizardzz 13-Jan-11 10:39am    
Very useful links.
Espen Harlinn 13-Jan-11 10:39am    
Well, thank you Marcus :)
Sergey Alexandrovich Kryukov 13-Jan-11 11:22am    
Espen, my 5.
Just a note on first reference: the article itself is not very good. Perhaps, just one line would be enough: use System.IO.FileSystemWatcher. This .NET class is a very good thing, but the production design relying on this is very bad.
Espen Harlinn 13-Jan-11 11:27am    
Thanks SAKryukov, the article was short, and that often seems to satisfy people more than a long treatise.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900