Retrieve Data from SharePoint Document Libraries (using SPServices)


This article describes how to retrieve data from a SharePoint document library using SPServices.


"SPServices is a jQuery library which abstracts SharePoint's Web Services and makes them easier to use.[...]1"


We will use a content Page in a SharePoint Online evironment, that contains a Inhalts-Editor/Content Editor Web-Part (CEWP). This CEWP needs to include the two JavaScript libraries jQuery and SPServices.


After creating a page and adding a CEWP, we have to set the source (HTML+JavaScript) of the web part. We recommend to use a separate source file which makes editing a bit more comfortable, i.e. create a .HTML-file and set its URL as the source of the web part. Furthermore, using a separate file enables you to use one of your favorite source code editores, e.g. Notepad++.

The source file at least has to contain the reference to the JavaScript libraries, a "local" script and a some HTML in order to display the results.

In our case, we have added a button that is automatically shown and to which a click handler is assigned when the document completed loading. This button triggers the query (getData function). The function sends an asynchronous request to the server and retrieves an XML response. The response is then shown as text in the section below the button and furthermore the XML is processed with the SPServices lib, finding all content rows. For each item in the list, an HTML unordered list (UL) element (LI) is added and the complete result is shown at the bottom of the document.

<script src="">


<script src="">





    $(function () {

        $('#go').show().click(function () {


            return false;





    function getData() {


            operation: "GetListItems",

            async: true,

            listName: "MyListName",

            /* we can also use the list id "{c991267a-05dc-462c-909c-ef6942fea145}", */

            completefunc: function (xData, Status) {


                $(xData.responseXML).SPFilterNode("z:row").each(function () {

                    var liHtml = "<li>" + $(this).attr("ows_LinkFilename") +

                        ' // ' + $(this).attr("ows_Modified") + "</li>";








<button id="go" style="display:none">Get Data</button>

<hr />

<label>Result XML:</label>

<div id="result" style="background:lightyellow; overflow-y:scroll;height:200px; width:800px;"></div>


<label>Result as list (UL):</label>

<div id="result-list" style="background:lightgray">

    <ul id="tasksUL" />



We were experiencing problems using version 1.9.1 of jQuery. The response did not deliver an xml-document, rather a response-text was returned which could not be processed with the SPServices lib. The responseXML was undefined, whereas the responseText was available. Switching to jQuery 1.9.0 solved the problem and the resultXML was retrieved correctly.


It is possible to files located subfolders with the following option:

// option to include subfolders

var options = "<QueryOptions><ViewAttributes Scope='RecursiveAll'/></QueryOptions>";



    operation: "YourListName",

    // include option to get files located in sub-folders

    CAMLQueryOptions: options,

    async: true,

    listName: DocLibDesign.settings.splib,

    completefunc: function (xData, Status) {

        if (Status == "success") {






Here is the Link to the working example. Pleae note, the SharePoint page is available to all authenticated users. At least a Microsoft account is needed to view the example.

Screenshot of the working example

working example preview

List of available attributes in z:row


ows_LinkFilename='Presentation 1 Report 2331 2013 Q1.pdf’

ows_Modified='2016-01-06 17:37:02’





ows_LinkFilenameNoMenu='Presentation 1 Report 2331 2013 Q1.pdf’







ows_Created_x0020_Date='27;#2016-01-06 17:19:14’


ows_FileLeafRef='27;#Presentation 1 Report 2331 2013 Q1.pdf’


ows_FileRef='27;#consulity/projects/mik/DocLibDesign/Presentation 1 Report 2331 2013 Q1.pdf’

ows_Editor='6;#consulity | Dieter Neumann’


ows_Last_x0020_Modified='27;#2016-01-06 17:37:01’


Dieter Neumann