Forum Discussion
how to create one-click direct download links on Image column in Sharepoint List
Hi there,
I've a sharepoint list by name "Employee Directory", this list have a column by name "Photo" where we store employee photo. I want this photo to be downloadable by just one click.
Is there a way to download photo by just clicking on it?
RezaDorrani
5 Replies
Hi!
you can use view formatting json for this:
https://learn.microsoft.com/en-us/sharepoint/dev/declarative-customization/view-formatting
Example code for creating this button and download image:
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/column-formatting.schema.json", "elmType": "button", "style": { "flex-direction": "column", "width": "80px", "border": "none", "border-radius": "3px", "margin": "10px 0" }, "attributes": { "class": "ms-bgColor-themePrimary" }, "children": [ { "elmType": "a", "txtContent": "Download", "style": { "color": "white", "text-decoration": "none", "padding": "12px 0px 12px 0px" }, "attributes": { "target": "_blank", "href": "= @currentWeb + '/_layouts/15/download.aspx?UniqueId=' + [$UniqueId]" } } ] }
- yunus96Copper Contributor
thanks NicolasKheirallah, for taking time to help me.
But it's downloading some other file with extension ".000". for examples its downloading file "94.000".
How do I set it to the image column in my list?Change to instead :
"href": "=@currentWeb+'/_layouts/15/download.aspx?sourceurl='+[$FileRef]"
Here is a finished code 🙂 create a random field for downloading and use format column
{ "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json", "elmType": "a", "txtContent": "Download", "style": { "background-color": "gray", "text-decoration": "none", "color": "white", "font-size": "14px", "padding-left": "5px" }, "attributes": { "target": "_blank", "href": "=@currentWeb+'/_layouts/15/download.aspx?sourceurl='+[$FileRef]" } }