SvgPublish and “enable custom scripts” setting

If you are using the SvgPublish add-in to export to SharePoint directly, you may face a message "Access Denied", although you have full (owner) access to the target site.

Meaning, after you click "Publish" in the SharePoint export dialog, you get the message:

file

The error happens after you click the "Publish" button in the SharePoint upload dialog:

file

Reason

The reason for this most probably is the block custom scripts setting. It is turned on by default on all modern SharePoint (or Teams) sites. If you are using SharePoint Online, in particular (group sites, communication sites).

This effectively means that no ".aspx" file can be uploaded there (even manually). To check you could try to upload a file with ".aspx" extension to the site (manually).

Please find more information regarding custom scripts/aspx page drawbacks here:
https://docs.microsoft.com/en-us/sharepoint/allow-or-prevent-custom-script

Enabling custom scripts

The "disable custom script" setting prevents any custom javascripts on the site. The SvgPublish extension uses JavaScript files to display the diagram, zoom/pan, sidebars, etc. And when it tries to configure/upload an .aspx page referring these files, it faces this block. For the upload to work, this setting needs to be turned off for now.

Starting with version 1.3, there is an option to enable that automatically for the target site on publishing. You must have the "owner" role for the target site to use this option. If you click "Yes" in the below dialog when prompted, the SvgPublish extension will enable scripts for the target site, and then upload the files:

file

Another way to enable the user script is to use PowerShell module:

Set-SPOsite $SiteURL -DenyAddAndCustomizePages 0

or SharePoint PnP:

Set-PnpTenantSite -Identity $SiteUURL -DenyAddAndCustomizePages:$false | Out-Null

The setting is per-site.

If this setting is turned on, nobody can do javascript or .aspx page customization on the side, even admins/owners. For the extension upload function to work, it needs to be off. Note that this setting prevents only upload but not display of the files. Meaning, if the files were already uploaded, and the setting is turned off, existing publication will still function.

Native SharePoint web part on the way

Good news: there is a new SvgPublish Web Part in development to provide a simple alternative to the current SharePoint upload.

The web part will also provide most of the options you can configure in Visio, but for a published diagram. Meaning, you will be able to customize look and feel of the "live" diagram already no the SharePoint page, and (optional of course) "full height" sidebar experience.

Leave a Reply