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);
binaryMessageCreator.CreateBinaryMessage(BinaryFileWithMetadata,base64String);
configProperties = new VdCruijsenNet.Utilities.Sharepoint.ConfigPropertiesXML();
configProperties.AddProperty("Title","test");
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.
Sendport
Receiveport
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




