The BizTalk SharePoint Messaging Adapter does not support the scenarios that are described in the "Summary" section. The correct way to save a document into the Outbox document library is to use managed code or scripts that perform a WebDAV
HTTP PUT Web request against the Outbox document library. Do this to persist the document in the Windows SharePoint Services site.
The BAS tutorial that is included with the BizTalk Server 2004 SDK provides samples that show how to do this. To view the BAS tutorial, visit the following Microsoft Web site:
The following file is available for download from the Microsoft Download Center:
Download the BizTalk Server 2004 Tutorials package now.Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. The following managed code and JavaScript code samples demonstrate the WebDAV HTTP PUT Web request for BizTalk Server 2004:
Managed code sample
// The following function handler is created by Microsoft Office InfoPath. Do not
// modify the type or number of arguments.
[InfoPathEventHandler(EventType=InfoPathEventType.OnSubmitRequest)]
public void OnSubmitRequest(DocReturnEvent e)
{
// If the submit operation is successful, set
// e.ReturnStatus = true;
// Write your code here.
// Create an XmlDocument object from the MSXML 5.0 object.
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
string xml = this.thisXDocument.DOM.xml;
doc.LoadXml(xml);
bool success = false;
// The URL of the following file can be computed from the Outbox URL.
// The Outbox URL can be retrieved by invoking the TPPubWS.GetOutboxDocumentLibraries method that is defined
// in the TPPubWS Web service. For additional information, see the BizTalk Server 2004 documentation.
success = PutUtf8File(xml,"http://<servername:serverport>/sites/BASSite/Outbox/Form2.xml", false);
e.ReturnStatus = success;
}
/// <summary>
/// The method uses WebDAV protocol to create a file at the specified URL.
/// The code performs an HTTP PUT Web request to create an UTF-8 encoded XML file
/// at the specified location on the Windows SharePoint Services site.
/// </summary>
/// <param name="utf8XmlDoc">XML document that has the encoding attribute set to "UTF-8" or has no encoding attribute at all.</param>
/// <param name="fileUrl">The URL where the document will be created. It must include the file name.</param>
/// <param name="overwrite">Set the value to true to overwrite the existing file or false to fail if a file that has the same URL exists.</param>
public static bool PutUtf8File(string utf8XmlDoc, string fileUrl, bool overwrite)
{
// HTTP Headers are used to control the overwrite behavior for HTTP PUT.
const string IfNoneMatchHeader = "If-None-Match"
const string IfNoneMatchValue = "*"
byte[] Buffer = null;
byte[] Preamble = null;
Stream outputFile = null;
HttpWebResponse Response = null;
HttpWebRequest PostFile = null;
HttpStatusCode statusCode = HttpStatusCode.ServiceUnavailable;
try
{
UTF8Encoding encoder = new UTF8Encoding();
Preamble = encoder.GetPreamble();
Buffer = encoder.GetBytes(utf8XmlDoc);
PostFile = (HttpWebRequest)WebRequest.Create(fileUrl);
PostFile.Method = "PUT"
if (!overwrite)
{
// Do not overwrite existing files.
PostFile.Headers.Add(IfNoneMatchHeader, IfNoneMatchValue);
}
// Use the client credentials when you save the file.
PostFile.Credentials = CredentialCache.DefaultCredentials;
// The content length must be set before you start to write data.
PostFile.ContentLength = Preamble.Length + Buffer.Length;
outputFile = PostFile.GetRequestStream();
// Write the byte order mark.
outputFile.Write(Preamble, 0, Preamble.Length);
outputFile.Write(Buffer, 0, (int)Buffer.Length);
if (outputFile != null)
{
outputFile.Close();
outputFile = null;
}
if (PostFile != null)
{
Response = (HttpWebResponse)PostFile.GetResponse();
statusCode = Response.StatusCode;
}
}
catch(System.Net.WebException we)
{
Response = we.Response as HttpWebResponse;
statusCode = Response.StatusCode;
}
finally
{
if (outputFile != null)
outputFile.Close();
if (Response != null)
Response.Close();
PostFile = null; // No Close or Dispose method exists for this object.
}
if ((statusCode == HttpStatusCode.OK) || (statusCode == HttpStatusCode.Created))
{
return true;
}
else if (statusCode == HttpStatusCode.PreconditionFailed)
{
// The file already exists.
return false;
}
else
{
// An error was encountered.
return false;
}
}
Javascript sample
//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
//=======
function XDocument::OnSubmitRequest(eventObj)
{
// If the submit operation is successful, set
// eventObj.ReturnStatus = true;
var success;
// The URL of the following file can be computed from the Outbox URL.
// The Outbox URL can be retrieved by invoking the TPPubWS.GetOutboxDocumentLibraries method that is defined
// in the TPPubWS Web service. For additional information, see the BizTalk Server 2004 documentation.
success = PutUtf8File(XDocument.DOM,"http://<servername:serverport>/sites/BASSite/Outbox/Form2.xml", false);
eventObj.ReturnStatus = success;
}
//=======
// The method uses the WebDAV protocol to create a file at the specified URL.
// The code performs an HTTP PUT Web request to create an UTF-8 encoded XML file
// at the specified location on the Windows SharePoint Services site.
// utf8XmlDoc - XML document that has the encoding attribute set to "UTF-8" or has no encoding attribute at all.
// fileUrl - The URL where the document will be created. It must include the file name.
// ovewrite - Set to value to true to overwrite the existing file or false to fail if a file that has the same URL exists.
//=======
function PutUtf8File(utf8XmlDoc, fileUrl, ovewrite)
{
// Create the xmlhttp object for transporting of the SOAP message.
var xmlhttp = null;
try
{
xmlhttp = new ActiveXObject("MSXML2.XMLHTTP.5.0");
// Save the message as a UTF-8 encoded XML document.
xmlhttp.open("PUT", fileUrl, false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
if (!ovewrite)
{
// Do not overwrite existing files.
xmlhttp.setRequestHeader("If-None-Match", "*");
}
xmlhttp.send(utf8XmlDoc);
}
catch(ex)
{
var constServerErrorExc = -2146697208;
if (ex.number != constServerErrorExc)
{
throw ex;
}
}
// Examine the HTTP response.
// Windows SharePoint Services returns 201 when a new file is created successfully
// or returns 200 if the content of an existing file has been updated successfully.
if ((xmlhttp.Status == 201) || (xmlhttp.Status == 200))
{
// Content has been saved successfully.
return true;
}
else if (xmlhttp.Status == 412) // Precondition failed.
{
// File already exists.
return false;
}
else
{
// An error was encountered.
var ErrorMessage = xmlhttp.statusText;
return false;
}
}