4

I am uploading files to SharePoint 2010 following the answer here: Uploading files to Document Libraries using the REST API

The issue is that all of the files are set as checked out due to some required fields in the list. I an using the OData API to update the column values, but I want to automatically check in the files. Is this even possible?

Here's how I'm updating the entities.

    Planning.PlanningDataContext context = new Planning.PlanningDataContext(new System.Uri("http://sharepoint/Service/ds/plan/_vti_bin/ListData.svc"));
    context.Credentials = System.Net.CredentialCache.DefaultCredentials;

    for (int i=0; i < Studies.Count; i++)
    {
        var study = Studies[i];
        PutFileOnSP(study);
        var serverStudy = context.GeotechnicalStudies.Where(s => s.Name == study.Name).FirstOrDefault();
        serverStudy.StudyArea = study.StudyArea;
        serverStudy.StudyPerformedBy = study.StudyPerformedBy;
        serverStudy.StudyNumber = study.StudyNumber;
        context.UpdateObject(serverStudy);
    }
    context.SaveChanges();
1

I don't believe it is possible using the ListData.svc. But you can do it using the Managed Client Side Object Model. I'm not on my dev system right now but I will add a code sample tomorrow.

Edit:

Just to be certain I attempted to check in a document in my dev server's Shared Documents library using ListData.svc. I attempted to do it by sending a DELETE request to

../_vti_bin/ListData.svc/SharedDocuments(1)/$links/CheckedOutTo

I did not receive any error but no modification was made. I also sent a POST request trying to set the CheckedOutToId to null. This didn't work either. So I honestly belive there is no way of doing this via the SP 2010 REST API. Here is example code using the Managed Client Object model. This was tested in a console app on my work laptop to my development server.

        ClientContext clientContext = new ClientContext("http://devserver.domain.com/");
        Web web = clientContext.Web;
        clientContext.Load(web);
        clientContext.ExecuteQuery();
        List sharedDocs = web.Lists.GetByTitle("Shared Documents");
        clientContext.Load(sharedDocs);
        clientContext.ExecuteQuery();
        ListItem item = sharedDocs.GetItemById(1);
        File file = item.File;
        file.CheckIn("Checkin comments.", CheckinType.MajorCheckIn);
        clientContext.Load(file);
        clientContext.ExecuteQuery();
0

It works with the SOAP interface of ShPt2010. (More recent versions have a slightly different interface, but still in SOAP.) The documentation is contained in any standard ShPt site (probably also yours), for example at https://www.h10hotels.com/_vti_bin/Lists.asmx?op=CheckInFile

Assuming your checked out file is https://example.net/subsite/Pages/file.aspx, then you can use an HTTP POST request with parameters

Content-Type: text/xml; charset=utf-8
SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/CheckInFile

and content

<?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>https://example.net/subsite/Pages/file.aspx</pageUrl>
            <comment>Describe what you did here.</comment>
            <checkinType>0</checkinType>
        </CheckInFile>
</soap:Body>
</soap:Envelope>

For example using a shell script and curl under Linux, you can implement this as follows:

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>https://example.net/subsite/Pages/file.aspx</pageUrl>
            <comment>Describe what you did here.</comment>
            <checkinType>0</checkinType>
        </CheckInFile>
</soap:Body>
</soap:Envelope>
EoSOAP
curl -d @- \
-H "Content-Type: text/xml; charset=utf-8" \
-H 'SOAPAction: "http://schemas.microsoft.com/sharepoint/soap/CheckInFile"' \
https://example.net/_vti_bin/Lists.asmx |
sed 's/.*<soap:Body>/\t/; s@</soap:Body>.*@\n@;'

(where the last line is just cosmetics to strip of the frame from the response to make it a bit nicer).

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.