0

It is possible to checkin a file to sharepoint document library using curl with the following command as mentioned in this question:

curl --ntlm --user username:password --upload-file file.txt https://mysharepointserver.com/sites/mysite/myfile.txt -k

But how to checkout the file first(using curl) from the document library?

I tried one method by passing SOAPAction checkoutfile headers and data as follows, but it had no effect eventhough the server returned response: '200 OK'

curl --ntlm --user username:password -d @soapdata.xml -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOutFile"  -H "Content-Type: text/xml; charset=utf-8" https://mysharepointserver.com/sites/mysite/myfile.txt -k

soapdata.xml contains the SOAP data needed for checkout as described by WSDL. Is there something wrong in above command or is there a simpler way to do this with CURL like the checkin case?

1
  • Are you sure the the uploaded file is also checked in as mentioned in your question? I am very curious to know as the file I uploaded did not get checked in as well. – RanonKahn Sep 6 '17 at 4:41
3

Thank you very much for this post. It was exactly what I was looking for. I imagine you left the CheckIn as an exercise for your readers? Here is my proposal (Bourne shell type, avoiding the intermediate file):

cat <<EoSOAP |
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <CheckInFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <pageUrl>tttps://myserver/sites/mysite/myfile.txt</pageUrl>
      <comment>Automagic update from bot</comment>
      <checkinType>0</checkinType>
    </CheckInFile>
  </soap:Body>
</soap:Envelope>
EoSOAP
curl -b $cookies -d @- \
  -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckInFile" \
  -H "Content-Type: text/xml" \
  https://myserver/sites/mysite/_vti_bin/Lists.asmx

(I replaced the authentication with NTLM by cookies, as used with Form authentication.)

It may be useful to specifiy that the /sites/mysite part of the URL contains the complete path down to the library, e.g. https://myserver/sites/topsite/subsite/mysite/Pages/ for a Page library.

The arguments for the SOAP operation, in particular CheckInFile, can be found on http://msdn.microsoft.com/en-us/library/lists.lists.checkinfile%28v=office.12%29.aspx

And you can get a quick reference of all SOAP operations implemented on your server with https://myserver/_vti_bin/Lists.asmx

3
  • I am not able to implement this in a Rshiny server dynamically as it involves embedding the file details in the xml. Any advice please? Should I create an xml file each time I upload and check-in a document? – RanonKahn Sep 5 '17 at 22:49
  • Thank you, @eric-alexander, for the edit. But you forgot one tttps occurence. :-( – Dirk Sep 25 '17 at 12:25
  • I don't know Rshiny, @RanonKahn. But this forum is about "sharepoint", and the question about "curl" (not libcurl). You will notice that the XML file in the answer above is 'piped' dynamically (inline) into curl by the shell. So I guess you will find a better and faster answer in an R related forum, by asking "how can I create a temporary/inline file/stream for output to curl" or so. But it seems to me that R supports libcurl, which would be the ideal choice then. – Dirk Sep 25 '17 at 12:34
1

Found from an example that, with SOAP approach, the URL in CURL command should be the path of the sharepoint site Lists.asmx and not the URL of file to be checked out. The file URL need to be only in the pageUrl field in soapdata xml as follows:

curl --ntlm --user username:password -d @soapdata.xml -H "SOAPAction: http://schemas.microsoft.com/sharepoint/soap/CheckOutFile" -H "Content-Type: text/xml; charset=utf-8" -k -v https://mysharepointserver.com/sites/mysite/_vti_bin/Lists.asmx

where contents of soapdata.xml:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <soap:Body>
    <CheckOutFile xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <pageUrl>https://mysharepointserver.com/sites/mysite/myfile.txt</pageUrl>
      <checkoutToLocal>true</checkoutToLocal>
      <lastmodified/>
    </CheckOutFile>
  </soap:Body>
</soap:Envelope>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.