How To

Export SharePoint Documents to a SQL Table in Binary Format

When exporting documents from a SharePoint document library to a SQL table you need to store the files in their binary format so then they can be used in other processes.

The following page covers how to export documents from a SharePoint document library to a SQL Table in their binary format.

Prepare the SQL Table

You need to make sure that your SQL Table has a column ready to hold your document with the data type set to varbinary.

SQL Table Design

Create the Data Sync Project

Now connect to your SharePoint Document Library and add the columns you want to the schema map. Connect to your SQL table on the target side and map the columns to their counterparts in the schema map.

Data Sync Project

You do not map the SQL table Document column in the schema map, this is handled by the next step.

To get the binary data into your SQL table change the connection property Blob Column on the SQL connection to be your Document column. Data Sync does all the work in the background so that this property will pull in the data to the column specified.

Blob Column Property

Now run the compare and Synchronise the changes.

Final Result

If we look at our SQL table we can see that documents have been added, and are showing as a Byte[] Array.

SQL Table Data

To make sure that this array has data if we run a SQL statement to get the data length of our Document column. The varying lengths show that data is contained within this column as each file contains different data.

Data Length