Upload SitePage, got "Sorry, you don't have access to this page"


Recently I wanted to upload customized modern SitePage (.aspx) to the Office 365 SharePoint Communication site SitePages, but couldn't. Here is how to do it.

My attempt to upload the SitePage.aspx using the modern SitePages library view didn't gave me any error, rejection or feedback, but the page was not uploaded. I went to classic document library view and then got the following error: "Sorry, you don’t have access to this page".

Sorry you don't have access to this page message when try to upload sitepage.aspx to SharePoint

Now I will execute SharePointPnPPowerShellOnline PowerShell script that requires tenant admin access to make it work for the site.

Prerequisites:
- Tenant admin access
- SharePointPnPPowerShellOnline already installed and ready to execute SharePointPnPPowerShellOnline PowerShell. See how to do it on that link


Import-Module -Name SharePointPnPPowerShellOnline -DisableNameChecking

$denyAddAndCustomizePagesStatus = [Microsoft.Online.SharePoint.TenantAdministration.DenyAddAndCustomizePagesStatus]

Connect-PnPOnline -Url 'https://<tenant>-admin.sharepoint.com'

$context = Get-PnPContext

$status = $null

do
{
    Write-Host "Waiting...   $status"
    Start-Sleep -Seconds 5
    $site=Get-PnPTenantSite -url https://<tenant>.sharepoint.com/sites/<siteCollection1> -Detailed
    $status = $site.Status
} while ($status -ne 'Active')

$site.DenyAddAndCustomizePages = $denyAddAndCustomizePagesStatus::Disabled

$site.Update()
$context.ExecuteQuery()

$site=Get-PnPTenantSite -url https://<tenant>.sharepoint.com/sites/<siteCollection1> -Detailed

$state = $site.DenyAddAndCustomizePages
Write-Host "Done...site.DenyAddAndCustomizePages:  $state"

Disconnect-PnPOnline

There is also community thread opened here: https://techcommunity.microsoft.com/t5/SharePoint-Developer/How-do-I-set-DenyAddAndCustomizePages-using-PnP/td-p/32372

Issues related to that execution code and Community sites: https://github.com/SharePoint/sp-dev-docs/issues/744

Sharing is Caring
Posted on

Tags: SitePage, PowerShell, Feature enable, SharePoint Online, Office 365 Dev, DenyAddAndCustomizePages, Team site, Communication site, Upload SitePage

Comments