I have used different methods to upload documents to SharePoint from BizTalk which includes using BizTalk SharePoint Adapter, Sharepoint Services and also by using SharePoint 2010 Client Object Model.
In this article i will use SharePoint Object Model to upload documents to SharePoint using BizTalk 2010.
I have a requirement where documents need to be uploaded to SharePoint 2010 from BizTalk. I have created a C# project which i will be using to reference SharePoint 2010 client objet model dlls. This project is referenced in BizTalk Orchestration project.
As a first step i will add SparePoint 2010 Client Object Model Dll’s. I have nuget installed so i will use nuget to download the package which will add the the dll references
If you do not have nuget, download the dll’s separately and reference to your project.
Reference the library in your Class as follows
Below is the code to upload documents to SharePoint 2010
using (ClientContext clientContext = new ClientContext(siteURL))
// Set Credentials
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(SharePointUsername, SharePointPassword, SharePointDomain);
clientContext.Credentials = credentials;
clientContext.RequestTimeout = 100000;
Web web = clientContext.Web;
//Get Document List
List documentsList = web.Lists.GetByTitle(sharePointLibrary);
//Load SharePoint library Lists
var fileCreationInformation = new FileCreationInformation();
fileCreationInformation.Content = System.IO.File.ReadAllBytes(receiveLocation);
fileCreationInformation.Url = sendLocation;
Microsoft.SharePoint.Client.File uploadFile = documentsList.RootFolder.Files.Add(fileCreationInformation);
In the expression Shape I will call the method to upload file using Client Object Model
The file will be uploaded and you will be able to see the documents in SharePoint.