You can attach documents to SharePoint list items. However if you add the “Attachments” column to your list views, you get a column that only shows a paperclip icon (see below) if there are any attachments. Clicking that paperclip also won’t open any attachment or the list item to view them. It’s strictly an image.

Here’s how you can replace that paperclip on each row with the actual name(s) of your attachment(s) linked to the actual attachment(s).
Download this code, or copy and paste it into a new file in your Site Assets folder as ShowAttachments.js:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script> | |
| <script type="text/javascript"> | |
| (function () { | |
| var attachmentsFiledContext = {}; | |
| attachmentsFiledContext.Templates = {}; | |
| attachmentsFiledContext.Templates.Fields = { | |
| "Attachments": { "View": AttachmentsFiledTemplate } | |
| }; | |
| SPClientTemplates.TemplateManager.RegisterTemplateOverrides(attachmentsFiledContext); | |
| })(); | |
| function AttachmentsFiledTemplate(ctx) { | |
| var itemId = ctx.CurrentItem.ID; | |
| var listName = ctx.ListTitle; | |
| return getAttachments(listName, itemId); | |
| } | |
| function getAttachments(listName,itemId) { | |
| var url = _spPageContextInfo.webAbsoluteUrl; | |
| var requestUri = url + "/_api/web/lists/getbytitle('" + listName + "')/items(" + itemId + ")/AttachmentFiles"; | |
| var str = ""; | |
| $.ajax({ | |
| url: requestUri, | |
| type: "GET", | |
| headers: { "ACCEPT": "application/json;odata=verbose" }, | |
| async: false, | |
| success: function (data) { | |
| for (var i = 0; i < data.d.results.length; i++) { | |
| str += "<a href='" + data.d.results[i].ServerRelativeUrl + "'>" + data.d.results[i].FileName + "</a>"; | |
| if (i != data.d.results.length – 1) { | |
| str += "<br/>"; | |
| } | |
| } | |
| }, | |
| error: function (err) { | |
| } | |
| }); | |
| return str; | |
| } | |
| </script> |
When on the list view for which you’re wanting to show attachments, edit the page (settings wheel –> edit page).

Add a web part.

Add a content editor web part.

Paste the URL to the script you saved earlier in the Content Link box.

Expand “Appearance” and set Chrome Type to “None” and click OK.

Save the page/stop editing.

That’s all there is to it!

Leave a Reply