Problem: Getting “Access Denied. You do not have permission to perform this action or access this resource” error when trying to upload a File or creating a folder in “Style Library”.
Also, we get a similar error when trying to create a new folder:
This is because the Custom script is disabled for the site collection. We have to enable custom script for the particular site collection to fix the issue. The custom script is disabled by default in modern team and communication sites.
How to Enable Custom Script in SharePoint Online?
Here is how to enable custom script in SharePoint Online:
- Login to SharePoint Online Admin Center
- Click on Settings from the left navigation >> Click on the “Classic Site Settings” link (https://tenant-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx) and scroll down to the “Custom Script” section.
- Set “Allow users to run custom script on personal site” and “Allow users to run custom script on self-service created sites” options.
- Click on “OK” to save your changes.
This enables custom scripts in SharePoint Online. However, this change may take up to 24 hours to reflect. To enable scripting on a particular site collection immediately, use this PowerShell script in SharePoint Online Management Shell.
PowerShell to Fix Access Denied Error on uploading Files in SharePoint Online Issue:
Use this PowerShell script to enable custom scripting instantly.
#Config Parameters $AdminSiteURL="https://crescent-admin.sharepoint.com" $SiteURL="https://crescent.sharepoint.com/sites/marketing" #Get Credentials to connect $Cred = Get-Credential #Connect to SharePoint Online Tenant Admin Connect-SPOService -URL $AdminSiteURL -Credential $Cred #Disable DenyAddAndCustomizePages Flag Set-SPOSite $SiteURL -DenyAddAndCustomizePages $False
This fixes the “Access denied. You do not have permission to perform this action or access this resource” Error on Uploading File or create a new folder in Style Library in SharePoint Online site collection.
Here is another article on enabling custom script in SharePoint Online: How to Enable Custom Script in SharePoint Online?