Back to column formats
Column formattingSharePoint Online

File Picker

This sample demonstrates how to prompt users to copy a file link from a specific library and displays it in the column.

File Picker formatting preview
Sample preview · View original animation

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": "div",
  "children": [
    {
      "elmType": "div",
      "style": {
        "display": "=if(length(@currentField)>0,'none','')"
      },
      "children": [
        {
          "elmType": "div",
          "style": {
            "width": "150px",
            "height": "30px",
            "border": "2px solid black",
            "cursor": "pointer"
          },
          "inlineEditField": "@currentField"
        },
        {
          "elmType": "div",
          "style": {
            "display": "=if(length(@currentField)>0,'none','flex')"
          },
          "children": [
            {
              "elmType": "a",
              "style": {
                "text-decoration": "none",
                "cursor": "pointer"
              },
              "attributes": {
                "href": "=@currentWeb+'[replaceUrlPathtoLibrary]'",
                "target": "blank",
                "title": "Select image",
                "iconName": "ImageSearch",
                "class": "ms-fontSize-20 ms-fontColor-themePrimary"
              }
            },
            {
              "elmType": "a",
              "style": {
                "text-decoration": "none",
                "padding-left": "5px",
                "cursor": "pointer"
              },
              "attributes": {
                "href": "=@currentWeb+'[replaceUrlPathtoLibrary]'",
                "target": "blank",
                "class": "ms-fontColor-themePrimary"
              },
              "txtContent": "Select image"
            }
          ]
        }
      ]
    },
    {
      "elmType": "div",
      "style": {
        "display": "=if(length(@currentField)>0,'','none')"
      },
      "children": [
        {
          "elmType": "a",
          "style": {
            "text-decoration": "none",
            "padding": "10px",
            "font-size": "32px",
            "cursor": "pointer"
          },
          "attributes": {
            "iconName": "Photo2",
            "href": "@currentField",
            "target": "_blank",
            "class": "ms-fontColor-themePrimary"
          }
        },
        {
          "elmType": "div",
          "style": {
            "cursor": "pointer"
          },
          "attributes": {
            "title": "Delete image",
            "iconName": "ErrorBadge",
            "class": "ms-fontColor-themePrimary"
          },
          "customRowAction": {
            "action": "setValue",
            "actionInput": {
              "FilePicker": ""
            }
          }
        }
      ]
    }
  ]
}

From the contributor

How to use this sample

Summary

This sample demonstrates how to prompt users to copy a file link from a specific library and displays it in the column.

screenshot of the sample

View requirements

  • This format can be applied to any Single line of Text Column with Title FilePicker.

Sample

Solution Author(s)
generic-filepicker.json André Lage
  • Replace [replaceUrlPathtoLibrary] with path to SharePoint Library, sample: '/SiteAssets/'

Version history

Version Date Comments
1.0 May 27, 2022 Initial release

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.