Achieving attachment url from List by Parsing XML in SharePoint 2010

InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can get attachment URL from list by parsing XML in SharePoint 2010.

Also you can check out:

– Create a Sequential workflow using visual Studio 2010 in SharePoint 2010

– Content management improvements in SharePoint 2013

– Replace “Add New Item” Link Text to something Different Link Text 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.”);
}
});
}

Similar SharePoint 2013 Tutorials


Leave a Reply