EnjoySharePoint YouTube Channel

Achieving attachment url from List by Parsing XML in SharePoint 2010


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.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

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

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials: