Hiding the New and Upload buttons from a SharePoint document library using JSON list formatting

Recently I got a query about hiding the New and Upload buttons for a SharePoint library, because there was a need to allow users to browse documents using out-of-the-box SharePoint views in a library while still having permissions to upload files so that they could upload files using an SPFx WebPart or a Canvas App.

This request can easily be achieved using list formatting, by adding customisations to the command bar to hide some buttons as below:

Items to hide/JSON content

Using list formatting, there is an option to hide an out-of-the-box SharePoint button from the command bar in a view (for both lists and libraries).

To hide the New and Upload buttons from a view, you can simply use the below JSON, by mentioning the command key, and the property ‘hide‘ as true:

{
    "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
    "commandBarProps": {
      "commands": [
        {
          "key": "new",
          "hide": true
        },
        {
          "key": "upload",
          "hide": true
        }
      ]
    }
  }
  

Although I also recommend if that is the purpose, you also hide the ‘Sync’, ‘Add shortcut to OneDrive’ and ‘Pin to quick access’ options, to avoid the users bypassing your custom upload form. You can use the below JSON formatting to do so:

{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/row-formatting.schema.json",
  "commandBarProps": {
    "commands": [
      {
        "key": "new",
        "hide": true
      },
      {
        "key": "upload",
        "hide": true
      },
      {
        "key": "sync",
        "hide": true
      },
      {
        "key": "addShortcut",
        "hide": true
      },
      {
        "key": "pinToQuickAccess",
        "hide": true
      }
    ]
  }
}

See below the difference from a view with all the buttons, and another with hidden buttons:

If you intend to hide the buttons for the whole library, you will need to apply the JSON formatting content in all library views.

Conclusion

By using a simple JSON formatting template, we are able to hide buttons from a view in SharePoint.

Important to note that, those customisations do not take effect on SharePoint mobile apps.

Reference

Command bar customization reference – Microsoft Learn

6 comments

  1. This is great – thanks! I have noticed though, I’m hiding the new button from each view. But my users need to have the ability to create new views, mainly private ones for themselves. When doing this, the ‘New’ button appears again. Any idea on how to hide it for all views including newly created ones? Cheers!

    1. If they don’t need to create items in the lists, you can create a custom permission level without the ‘add items’ permissions and assign it to the group/place you grant access to those users…
      This post’s scenario is useful if they still need access from other tools (like Power Apps or custom WebParts). Otherwise playing with the permissions will be easier.

Leave a Reply

Your email address will not be published. Required fields are marked *