Add documents from a Base64Binary xml element to SharePoint with Biztalk 2006

On my current project we wanted to add documents which come in as attachment through a webservice to a sharepoint document library to store them.

We used Biztalk 2006 to receive the file, get the different files from the xml and then send them to SharePoint. In this blogpost I’ll explain how to do this with a small POC I made.

First off we started with a receive port which is able to receive the xml message (the binary port on the picture) we receive this message into a BinaryMessage message which is linked to the following schema

An example message is looking like this: (where the <document> should have the attachments as a base64binary string.

After receiving the message we want to loop through all the messages in the document so I created a foreach to read all the document elements from the xml.

The code to build the loop is the following:

InitializeLoop :

iteration = 1;

documentCount = xpath(BinaryFile,"count(/*[local-name()='BinaryFileToSharePointTest' and namespace-uri()='']/*[local-name()='Document' and namespace-uri()=''])");

first I set the iteration variable to 1 and I set the documentCount to the amount of document elements that are in the incoming xml file.

Message assignment

BinaryFileWithMetadata = BinaryFile;

binaryMessageCreator = new BinaryToSharePoint.Helper.BinaryMessageCreator();

selectXpath = "string(/*[local-name()='BinaryFileToSharePointTest' and namespace-uri()='']/*[local-name()='Document' and namespace-uri()='']["+ System.Convert.ToString(iteration)+"]/text())";

base64String = xpath(BinaryFile,selectXpath);


configProperties = new VdCruijsenNet.Utilities.Sharepoint.ConfigPropertiesXML();


BinaryFileWithMetadata(WSS.ConfigPropertiesXml) = configProperties.ToString();

BinaryFileWithMetadata(WSS.Filename) = "bestandsnaamTest "+System.Convert.ToString(iteration)+".pdf";

In the message assignment we first Create the new outgoing message for each of the documents in the incoming xml file. Then we select the base64binary string with an xpath expression and send it to the binaryMessageCreator.

The binaryMessageCreator creates a new System.Xml.Document (which isn’t a xml file but biztalk doesn’t know that :) from the base64binary string. For the source of the BinaryStreamFactory see below:

After creating the new Message of the type System.Xml.Document, which is actually a byte[] containing the file we add a filename and some metadata which can be stored in SharePoint we send the message with the send shape to sharepoint.

The SendPort is a “Windows SharePoint service” sendport which can automatically add the file to a sharepoint document library.




As you can see it’s pretty easy to get the binary files from an xml file in Biztalk after you know how you can do it.

Happy Coding

Geert van der Cruijsen

Share on Facebook
Kick It on
Shout it
Post on Twitter

Upgraded my weblog to 1.4.5

4 days ago 1.4.5 was released. A good time for me to upgrade to the newest version since i wanted to split my weblog up to a part to store my messages about my private life and my posts about software development.

Upgrading to 1.4.5 was pretty easy except 1 error i ran into. I’m using together with mysql since my provider doesn’t have mssql and I didn’t really like the xml based blogging. After setting everything up i kept on running into System.Threading.SemaphoreFullExceptions. After posting this on the codeplex site some people mentioned this was a bug in the version 5.1.6 and if you upgrade to 5.2.2 everything should work fine again. So i did and you can see the results now.

I’ve also upgraded the layout of my weblog and added a section to store my weblog about my life when I’m not developing software but am going out on vacation, trips or have something else to blog about.

Tnx to the team for this great piece of software!

Geert van der Cruijsen


Share on Facebook
Kick It on
Shout it
Post on Twitter