Achieving attachment url from List by Parsing XML in SharePoint 2010

InfoPath alternatives for form designing SharePoint

This SharePoint tutorial explains, how we can get attachment URL from list by parsing XML in SharePoint 2010. Below code can be used to get the attachment URL of any list item by just passing the item ID.

function getAttachmentURL(id , callback)
{
var requestUri = _spPageContextInfo.webAbsoluteUrl + “/_api/web/lists/getbytitle(‘Announcements’)/items(‘”+id+”‘)/AttachmentFiles” ;

$.ajax({
type: “GET”,
url: requestUri,
dataType: “xml”,
async:false,
success: function(xml){


xmlDoc = (new XMLSerializer()).serializeToString(xml);
xmlDoc = xmlDoc.replace(/d:ServerRelativeUrl/g, ‘ServerRelativeUrl’);
//alert(xmlDoc);
callback($(xmlDoc).find(“ServerRelativeUrl”).text(),title,body,data);

},
error: function() {
alert(“An error occurred while processing XML file.”);
}
});
}


You May Also like the Following SharePoint Online Tutorials:

Leave a Reply