Publish a file with OfficialFile.asmx

Coordinator
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.
Coordinator
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?

M.
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="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">\
                          <soap12:Body>\
                            <SubmitFile xmlns="http://schemas.microsoft.com/sharepoint/soap/recordsrepository/">\
                              <fileToSubmit><![CDATA[' + B64.encode(byteData) + ']]></fileToSubmit>\
                              <properties>\
                                ' + properties + '\
                              </properties>\
                              <recordRouting>Test Document</recordRouting>\
                              <sourceUrl>' + host + "/" + fileServerRelativeUrl + '</sourceUrl>\
                              <userName>' + currentUserLoginName + '</userName>\
                            </SubmitFile>\
                          </soap12:Body>\
                        </soap12:Envelope>';

        var xmlhttp = new XMLHttpRequest();
        xmlhttp.open('POST', webUrl + '/_vti_bin/officialfile.asmx', true);
        xmlhttp.setRequestHeader('Content-Type', 'application/soap+xml; charset=utf-8');
        xmlhttp.setRequestHeader('SOAPAction', 'http://schemas.microsoft.com/sharepoint/soap/recordsrepository/SubmitFile');
        xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4) {
                if (xmlhttp.status == 200) {
                    deleteItem(listItem);
                }
            }
        }
        xmlhttp.send(soap);

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

M.
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.

/Stefan
Coordinator
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.
Coordinator
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!

m>