Forum Discussion

patrickige's avatar
patrickige
Copper Contributor
Jan 02, 2025

Open pdf documents in a new window - SharePoint Online

Is it possible to Show link to document in SharePoint if file_x0020_type is PDF and add a link to open file in native PDF using JSON formatting?

Happy News Year and thanks in advance.

  • michalkornet's avatar
    michalkornet
    Iron Contributor

    Hi patrickige  do you mean something like this?

    {
      "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
      
      "elmType": "a",
      "txtContent":"=@currentWeb + '/Shared%20Documents/' + [$FileLeafRef]",
      "attributes": {
        "href": "=@currentWeb + '/Shared%20Documents/' + [$FileLeafRef]",
        "target": "_blank"
      },
      "style": { "display": "=if(substring([$FileLeafRef], indexOf([$FileLeafRef], '.') + 1, indexOf([$FileLeafRef] + '^', '^'))== 'pdf', 'block', 'none')" }
    }

     

Resources