Back to column formats
Column formattingSharePoint Online

Download File Button

This sample demonstrates adding a button within a document library view which downloads the file.

generic-comment-count
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "button",
  "style": {
    "border-radius": "5px",
    "margin": "5px 0px",
    "padding": "0px",
    "visibility": "=if([$File_x0020_Type] == '', 'hidden', 'visible')"
  },
  "attributes": {
    "class": "ms-bgColor-themePrimary"
  },
  "children": [
    {
      "elmType": "a",
      "txtContent": "Download",
      "style": {
        "text-decoration": "none",
        "padding": "10px 0px",
        "width": "100%"
      },
      "attributes": {
        "href": "= @currentWeb + '/_layouts/15/download.aspx?UniqueId=' + [$UniqueId]",
        "target": "_blank",
        "class": "ms-fontColor-white"
      }
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates adding a button within a document library view which downloads the file.

screenshot of the sample

View requirements

This format can be applied to any column type (its value is ignored).

Sample

Solution Author(s)
generic-download-file-button.json Ganesh Sanap

Version history

Version Date Comments
1.0 January 05, 2022 Initial release
1.1 January 07, 2023 Changed button hide condition.

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.