Friday, June 8, 2007

SharePoint List Importer/Exporter: Part I

Most companys I work with aleady have some form of Intra/Inter net already in place, that they want to port over to SharePoint. These installations often take the form of a threaded discussion forum or database.



I must admit I am not entirely happy with the way lists and items are displayed in Sharepoint

But that is another topic.

I did see a need to import folders and items into a list.

So I created an import utility to read a list of items from a CSV file and store them in a data table. Then I streamed in a CSV file with a list of folders, matched on a key value and created the folder and added the items into it.

I started by exporting a view of folders to a CSV file. I included the key field and about 4 columns of data. Then I filtered the view on items and exported the items to a CSV, once again adding the key field and some columns.

I created a small xml settings file:

<ActionDefinition Run="false" Desc="EXAMPLE - Import Folders and Items into new List">
<Url>http://moss/docs/</Url>
<ListName>My List</ListName>
<ListTitle>My Folders and Items</ListTitle>
<FilePath>C:\folders.csv</FilePath>
<SubFilePath>C:\items.csv</SubFilePath>
<KeyColumn>FolderID</KeyColumn>
<LinkFormat>href={0} class='link'{1}</LinkFormat>
<RunAction>Imports</RunAction>
<CreateType>FolderItems</CreateType>
</ActionDefinition>


The file specifies the action: Import or Export; the url of the list (in this case I am creating a new list called 'My List'); the paths to the files, the keycolumn name in the files; and some formatting information.

The only formatting I had to do in the ffiles was to add 3 lines to the top of the file. These lines defined FieldName, FieldType and Required. So my folders file looked like...

FolderID,Field1,Field2,Field3,Field3
Number,Text,Text,Text,Text
true,false,false,false,false
1102,Michael,J.,Meyer,"Accounting Services"
1112,Tim,,Meyer,"Professional Services"

I created a small console application that reads from the xml settings and loads the settings

The code that processes the information I will include in Part 2....

JMC

1 comment:

Rash Vyas said...

Hi, This is very nice..I will really appreciate if you could help me. I have .csv file which 4 colomns
Date,Time,Username,Group. Every month my script generates this .csv file which I want to import in Sharepoint data list. I am new to Sharepoint, so any help will be appreciated.