This project has moved and is read-only. For the latest updates, please go here.

Publish a file with OfficialFile.asmx

Apr 24, 2014 at 4:39 PM
From Stefan Bauer on Twitter:

@sympmarc Have you ever tried to publish a file to SharePoint using web services?
@sympmarc Upload to OfficialFile asmx /_vti_bin/officialfile.asmx actually the method send.
@sympmarc Thanx. Text File work perfect but not when I send a word document. Must be something with the encoding.
Apr 24, 2014 at 4:39 PM
I can't recall having used this service, and it's not wrapped in SPServices, but it could be. Want to explain a bit more what you're doing?

Apr 24, 2014 at 9:47 PM
Hi Marc,

thank you for your help. Let me first describe the setup. I use a document center and try to force the routing to the destination library. A normal update won't work to move the file. On a document center or recored center you have to use the web service OfficialFile.asmx. Previously I always got a 400 Bad Request.

Finally I found the solution to this problem. First the content of the file needs to be encoded to Base64 and the second thing is to wrap the content in a CDATA. After I added this to my code the routing works really charming.
    var moveFile = function (listItem, properties, byteData) {

        var soap = '<?xml version="1.0" encoding="utf-8"?>\
                        <soap12:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap12="">\
                            <SubmitFile xmlns="">\
                              <fileToSubmit><![CDATA[' + B64.encode(byteData) + ']]></fileToSubmit>\
                                ' + properties + '\
                              <recordRouting>Test Document</recordRouting>\
                              <sourceUrl>' + host + "/" + fileServerRelativeUrl + '</sourceUrl>\
                              <userName>' + currentUserLoginName + '</userName>\

        var xmlhttp = new XMLHttpRequest();'POST', webUrl + '/_vti_bin/officialfile.asmx', true);
        xmlhttp.setRequestHeader('Content-Type', 'application/soap+xml; charset=utf-8');
        xmlhttp.setRequestHeader('SOAPAction', '');
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {

Thank you for your proposal to help.
Apr 24, 2014 at 10:46 PM
Excellent! Would it be helpful to have this service in SPServices?

Apr 24, 2014 at 11:05 PM
Probably because with this web service you can handle the document routing in SharePoint really well once you have this running. In our case we us it to bulk submit documents out of the drop off library.
Someone only needs to check if all the correct meta data are there. For this the list view is enough and you don't have to open every single document.

May 5, 2014 at 2:42 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Oct 23, 2014 at 10:47 PM
I'm adding the OfficialFile Web Services into 2014.02ALPHA6, which I'll publish shortly. If you have time to test it, that would be great!