Access Denied Error on Styles Library

I am going to file this one under the “if you need to do something more than twice you should probably write it down”. This gets me frequently enough that I remember I’ve dealt with it before but not frequently enough that I can commit the solution to memory. I find myself using the SPFX React Menu extension quite a bit as a base for creating custom navigation controls. The navigation on that extension is powered by a json file that is uploaded to the Styles Library. In an OOTB site I whenever I try to upload the json file to the Styles Library I get an access denied error. Other traditional files like .txt or .docx work just fine.

Here is the PowerShell that I use to allow custom scripts. I got it from Antti Koskella.

# If you don't already have the modules, run Install-module first!
Import-Module -Name SharePointPnPPowerShellOnline -DisableNameChecking
 $adminUrl = "https://mytenant-admin.sharepoint.com/"
$siteurl = "https://mytenant.sharepoint.com/sites/MySiteUrl"

Connect-PnPOnline -Url $adminUrl -Credentials (Get-Credential)
 
$DenyAddAndCustomizePagesStatusEnum = [Microsoft.Online.SharePoint.TenantAdministration.DenyAddAndCustomizePagesStatus]
 
$context = Get-PnPContext
$site = Get-PnPTenantSite -Detailed -Url $siteurl
 
$site.DenyAddAndCustomizePages = $DenyAddAndCustomizePagesStatusEnum::Disabled
 
$site.Update()
$context.ExecuteQuery()
 
Disconnect-PnPOnline

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.