GetAttachmentCollection Example

Oct 24, 2012 at 9:04 PM

Of all of the times I've used this library, I don't think I've ever used this operation.  Here's an example for future usage:

	$().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 );
		}
	});

Cheers,
Matthew

Jun 28, 2013 at 7:54 PM
Used this to custom render a SharePoint Announcement list containing attachments. Perfect. Thanks for the example.
Mar 26, 2014 at 6:58 PM
Beautiful and Perfect, thank you very much.
Coordinator
Mar 31, 2014 at 2:15 PM
Added the example to the documentation. I missed it the first time. Thanks, Matt!

M.