Function

$().SPServices

Web Service

Lists

Operation

GetAttachmentCollection

Notes

  • This operation accepts a webURL option. This allows you to change the context for the operation to a different site. Using a GUID for the listName does NOT change the context as it does with the Object Model, so you need to use the webURL option as well if your list is in a different site.

Example

This is an example from Matt Bramer (iOnline247) from his post in the discussions.

$().SPServices({
  operation: "GetAttachmentCollection",
  listName: "MahAwesomeListName",
  ID: id,
  completefunc: function(xData, Status) {
    //console.log( Status );
    //console.log( xData.responseText );

    var output = "";

    //debugger;

    $(xData.responseXML).find("Attachments > Attachment").each(function(i, el) {
      var $node = $(this),
        filePath = $node.text(),
        arrString = filePath.split("/"),
        fileName = arrString[arrString.length - 1];

      output += "<a href='" + filePath + "' target='_blank'>" + fileName + "</a><br />";
    });

    $("#drop-zone").html(output);
  }
});

Last edited Mar 31, 2014 at 2:14 PM by sympmarc, version 1

Comments

Rothrock42 Oct 22, 2015 at 12:59 AM 
I couldn't get this to work. Nor could I get the solutions presented about using the CAMLQueryOptions include all attachments to work.

What did work was just adding "Attachments" to the list of fields I wished to retrieve.

Senior_MelviN Jun 26, 2015 at 12:32 PM 
This code (Example) not working. Working this: https://deversoy.wordpress.com/2014/09/10/get-attachments-using-spservices-in-sharepoint-2013/comment-page-1/