How to resolve 404 error in SharePoint List attachment in SharePoint online/Office 365/SharePoint 2010/2013/2016?

Hello SharePointers,

When you try to download a file attachment, there are time you receive “404 not found” Error. You need to rebind the onlick event using Content editor web part like below

 

<Script type=”text/javascript”>
var attachmenttable = document.getElementById(“idAttachmentsTable”);
var attachmentanchor = attachmenttable.getElementsByTagName(“a”);
for (var j = 0; j < attachmentanchor.length; j++)
{
var attachmentonclick = attachmentanchor[j].getAttribute(“onclick”);
var attachmenthref = attachmentanchor[j].getAttribute(“href”);
var neweventattachmentonclick = “STSNavigate(‘/_layouts/download.aspx?SourceUrl=” + dllattachmenthref + “‘)”
var neweventattachmenthref = “javascript:STSNavigate(‘/_layouts/download.aspx?SourceUrl=” + dllattachmenthref + “‘)”

document.getElementById(“idAttachmentsTable”).getElementsByTagName(“a”)[j].setAttribute(‘onclick’,neweventattachmentonclick );
document.getElementById(“idAttachmentsTable”).getElementsByTagName(“a”)[j].setAttribute(‘href’,neweventattachmenthref );

} </script>

Happy SharePointing Folks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *