Office 365 – SharePoint Online – “Access Denied” error while uploading custom template for “Document” content type
Today new issue and solution 🙂
Background: In one of our SharePoint Online project we have requirement to create the custom document template. So we created custom content type derived from OOB Document content type. Since this is one time activity we thought to do it simply from the UI.
We created our custom document template and saved it locally. We went to “Advanced Settings” of content type and try to upload the our custom template as
Fig 1 : Office 365 – SharePoint Online – Advance Settings of Document content type
NOTE: Account though which we logged in to our SharePoint online site is “Global Administrator” and “SiteCollection Administrator” .
As soon as we clicked on OK button we are redirected to “AccessDenied.aspx” page as
Fig 2 : Office 365 – SharePoint Online – Access Denied error while uploading custom document template for content type
Solution: I was wondering the account using which we are logged in to the site has “Global Administrator” and “SiteCollection Administrator” rights and still “Access Denied” error 🙁
After bit thinking and googling it seems to be issue with custom scripts. By default custom script disabled at tenant level as
Fig 3 : Office 365 – SharePoint Online – Tenant Level Setting – Custom Script – By default disabled
We need to enable the “custom script” feature for the site. We can enable custom script from “Settings” options from SharePoint admin center which affects whole tenant or at site level using PowerShell cmdlets.
There are security implications by enabling custom scripts. Must read article for the same – Security considerations of allowing custom script
But since we need to upload custom template, we will enable custom script for our given site using PowerShell cmdlet.
Following are the steps to enable the custom scripting using PowerShell script
- Open “SharePoint Online Management Shell”
- Connect to Office 365 using SharePoint admin URL as
PS C:\> Connect-SPOService cmdlet Connect-SPOService at command pipeline position 1 Supply values for the following parameters: Url: https://knowledgejunction-admin.sharepoint.com
- Verify the default settings for your site once as
PS C:\> Get-SPOSite https://knowledgejunction.sharepoint.com/sites/config | fl Title : Configuration AllowSelfServiceUpgrade : True DenyAddAndCustomizePages : Enabled
- From above script result, it seems “DenyAddAndCustomizePages” is enabled by default. We need to disable as
PS C:\> Set-SPOSite https://knowledgejunction.sharepoint.com/ sites/config -DenyAddAndCustomizePages 0 PS C:\> Get-SPOSite https://knowledgejunction.sharepoint.com/sites/config | fl Title : Configuration AllowSelfServiceUpgrade : True DenyAddAndCustomizePages : Disabled
Once we enabled custom script we are successfully upload the custom template for the content type 🙂
Thanks for reading 🙂
Keep reading, share your thoughts, experiences. Feel free to contact us to discuss more. If you have any suggestion / feedback / doubt, you are most welcome.
Stay tuned on Knowledge-Junction, will come up with more such articles.