Aidan Garnish
MOSS 2007 and other Microsoft technologies

Generic CSV or SQL data importer for SharePoint list

September 9, 2008 17:01 by Aidan

I finally got bored of rewriting the same console application to move data from a csv or a sql table into a SharePoint list! The result is a generic console application that is capable of importing either a CSV file or some SQL data from a stored procedure. The app uses the object model so it needs to be run on the SharePoint server farm. I may get round to rewriting it using web services at some point. The CSV import parses the file so that things like line breaks and commas within fields are handled nicely. Any blank fields in the CSV do need to be filled using find and replace on blank space otherwise data ends up in the wrong columns.

To import a CSV the first row of the of the CSV file is used to define which columns the data will import to. Eg. A CSV that has one column with a header of Title will import the data into the Title column of the specified list. Modify the App.Config file to include the URL of your site collection, the list name, the path to the CSV and whether or not you want to delete all items in the list before importing.

To import SQL data create a stored procedure that returns the data as the names of the site columns

Eg. Select Name AS Title from tblPerson - will return one column of data that will import into the Title column of a list. Modify the App.Config to include the name of the stored procedure and the SQL connection string and run the app.

You can download the project from the following link:

AG.GenericSharePointListImporter.zip (41.72 kb)

This application is supplied as is and offers no guarantees feel free to use as you wish all I ask is that if you make any improvements then you share them in the comments or by email.

Technorati Profile

Currently rated 3.0 by 2 people

  • Currently 3/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Related posts

Comments

November 3. 2008 16:42

Hello,

your project seems to be exactly what I was looking for since....so long...
I've downloaded it, and when I try to run the compiled exe , I get an error message "Value does not fall within the expected range."
I use a SQL 2005 database, I created the stored proc, I modified the app.config ,built with Visual C# 2008 express, but no way,...I always get this error.
As I'm not a specialist about C#, could you please explain me how I can run it ??
Thanks a lot in advance,
Florence

Florence

December 15. 2008 18:07

Is there any Generic CSV or SQL data importer for wordpress, I try to find out but I could not find anything Frown

Busby SEO Test

December 19. 2008 07:24

is it possible to run the list checking realtime on demend rather than importing the data into list.

the code u had a link is external application. are we supposed to generate the lists from outside. i would prefer to create them when use clicks on the list.

Developer

December 30. 2008 14:43

@Florence - You will need to alter the App.Config file to point at the list you want to import into. Currently the application is looking for a list that does not exist on your SharePoint site and throwing the error you are seeing.

@gi621 - You could wrap this application as part of a feature that creates a SharePoint list. You could run the code as part of a feature receiver to import your CSV after the list is created.

Aidan

Add comment


 

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

January 6. 2009 14:27