SharePoint Experts, Information Architects, Expert Witness

We provide consulting in a broad array of business and technology from architecture to design to deployment of global systems with a focus on surfacing data in the enterprise. Specialists in Microsoft, we are a premier provider of SharePoint Expertise (including 2016 and Office 365). We also provide Expert Witness/Legal Expert in eDiscovery, source discovery, patent infringement, piracy and more! We also have established SICG DLDS s.a. - our counterpart in Costa Rica that specializes in water systems ( - Contact me direct: or call 704-873-8846 x704.

Search This Blog

Saturday, December 17, 2016

Creating Site Templates in SharePoint 2016 and SharePoint Online (including Publishing sites!)

Like many of you, I was dismayed to find that SharePoint Online can't be used to create templates and have always not liked being able to save a Publishing Site as a template.

In SPO, Microsoft says that since they automatically turn on Publishing that it cannot be done and that turning off publishing (which has to be done for the entire site collection) won't fix it because there are other features that are enabled. If you test it out, you'll find this to be the case.

In SP on premise, Microsoft disables the option to save publishing sites, however use either Workaround below and it does!

WARNING 1: If you try to save a site with content, most commonly a publishing site, it will FAIL if there is too much content. Best to save with a near-empty site!

WARNING 2: When you save a publishing site as a template using Metadata Navigation, the Navigation will be screwed up when you create a site from the template. It has to be reset to fix it through Site Settings > Navigation.

So - two ways to set the property to enable saving as a template:

Workaround 1:

* THIS works in the on premise version.

Another way to get around it is through SharePoint Designer:

Workaround 2:

* THIS works in the online version.

ANOTHER way to set the property in SharePoint Online is through the SharePoint Online Management Shell (setting the Property Bag):

$SiteUrl = ""
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$sUserName = ""
# Prompt for Password:
$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString
# Set the Site URL:
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword) 
$context.Credentials = $spoCredentials
$web = $context.Site.RootWeb
$web.AllProperties["SaveSiteAsTemplateEnabled"] = "true"

* This doesn't always work on Publishing Sites so I'd suggest using the Designer method.

However, I found that these solutions don't always work, particularly in SharePoint Online. There are hidden features (i.e. can't be turned on through the UI) that prevent the template from working in other site collections. I did however finally find a way to get it to work using the SharePoint Online Management Shell. By running the following script on the site collection, it enables all of the features you need to get the templates to work.

Once this script is run, you can go to the site you want to make a template of and simply alter the URL - so:


Kudos to the following post:

Here's the script - simply set the account name and the URL path to the site collection accordingly.

NOTE: You have to get a copy of the DLL's necessary for the following lines:

Add-Type -Path "C:\temp\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\temp\Microsoft.SharePoint.Client.Runtime.dll"

If you have an on-premise copy, you get get them from the ISAPI folder:
c:\program files\common files\microsoft shared\web server extensions\15\ISAPI

OR download them from here:

To use a template, you have to enable these features at the TOP LEVEL site collection; that is, say you create a template in Collection 1, you have to enable these features to use the template in Collection 2. 

$host.Runspace.ThreadOptions = "ReuseThread"
#Definition of the function that allows to enable a SPO Feature
function Enable-SPOFeature
param ($sSiteColUrl,$sUserName,$sPassword,$sFeatureGuid) 
#Adding the Client OM Assemblies 
Add-Type -Path "C:\temp\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\temp\Microsoft.SharePoint.Client.Runtime.dll"
#SPO Client Object Model Context 
$spoCtx = New-Object Microsoft.SharePoint.Client.ClientContext($sSiteColUrl) 
$spoCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($sUsername, $sPassword) 
$spoCtx.Credentials = $spoCredentials
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
Write-Host "Enabling the Feature with GUID $sFeatureGuid !!" -ForegroundColor Green
Write-Host "----------------------------------------------------------------------------" -foregroundcolor Green
$guiFeatureGuid = [System.Guid] $sFeatureGuid
$spoSite.Features.Add($sFeatureGuid, $true, [Microsoft.SharePoint.Client.FeatureDefinitionScope]::None) 
catch [System.Exception]
write-host -f red $_.Exception.ToString() 

# Required Parameters

# Modify Username above with your administrator credentials:
$sUserName = ""

# Prompt for Password:
$sPassword = Read-Host -Prompt "Enter your password: " -AsSecureString

$sSiteColUrl = ""
# Modify feature ID as needed (this one is MobileExcelWebAccess needed to use templates):
$sFeatureGuid= "e995e28b-9ba8-4668-9933-cf5c146d7a9f"
# Enable it (MobileExcelWebAccess): 
Enable-SPOFeature -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid 
# Library and Folder Based Retention - LocationBasedPolicy Feature
$sFeatureGuid= "063c26fa-3ccc-4180-8a84-b6f98e991df3"
# Enable it (LocationBasedPolicy): 
Enable-SPOFeature -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid 
# Site Policy - ProjectBasedPolicy Feature
$sFeatureGuid= "2fcd5f8a-26b7-4a6a-9755-918566dba90a"
# Enable it (ProjectBasedPolicy): 
Enable-SPOFeature -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid 
# Three-state workflow - IssueTrackingWorkflow Feature:
$sFeatureGuid= "fde5d850-671e-4143-950a-87b473922dc7"
# Enable it (IssueTrackingWorkflow): 
Enable-SPOFeature -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid 
# SitePageResources Feature
$sFeatureGuid= "ff77ac56-88d0-4147-b865-e84f5f03fc42"
# Enable it (SitePageResources): 
Enable-SPOFeature -sSiteColUrl $sSiteColUrl -sUserName $sUserName -sPassword $sPassword -sFeatureGuid $sFeatureGuid 

Opening Documents in a New Window (SharePoint Online 2013/2016)

Ever wanted SharePoint Online Documents to open in a new window?

As many have needed to, some want to be able to open documents from SharePoint Online in a new window instead of the same window - useful when you have to edit a number of documents at the same time.

I looked for several solutions - most didn't work however, I found one that did after making a few tweaks.

This minor modification enables you to set it on a library by library basis or you can save the library as a template once the script is put in a set place. Once you add it to the library view page, it applies TO ALL Views in the library.

NOTE: This does make a change to the way a library works - when you add a content editor web part to a library view, it HIDES the Files/Library tabs! Thanks for the bug but there is a work around.

To get started, here's the script - taken & modified from - the original script from there didn't work for me so I modified it for Office 365/SharePoint Online:

<script type="text/javascript">
// Create a namespace for the functions so we don't collide with anything else:
var customFunctions = customFunctions || {};
// Create a function for customizing the Field Rendering of our display fields:
customFunctions.CustomizeOpenFieldInNewTab = function () {
    var fieldJsLinkOverride = {};
    fieldJsLinkOverride.Templates = {};

    fieldJsLinkOverride.Templates.Fields =
        // Make sure the Your field view gets hooked up to the method defined below
        'LinkFilename': { 'View': customFunctions.GetDocumentsField },
    // Register the rendering template
    //   SPClientTemplates.TemplateManager.RegisterTemplateOverrides(fieldJsLinkOverride);
// Create a function for setting the proper URL to open in new window:
customFunctions.GetDocumentsField = function (ctx) {
    var myColumn = ctx.CurrentItem.ServerRedirectedEmbedUrl;
    var myFileName = ctx.CurrentItem.FileLeafRef;
    var editFileLink = myColumn.replace("interactivepreview", "default");
    var myIndex = myFileName.lastIndexOf(".");
    myFileName = myFileName.substring(0, myIndex);
    // Change the default URL to use Open in New Window:
    if (myColumn) {
        return "<a href='" + editFileLink + "' target='_blank'>" + myFileName + "</a>";
    return ctx.CurrentItem.ServerRedirectedEmbedUrl;
// Call the function:

First, save this script to a text file - i.e. OpenInNewWindowForView.txt.

Step 1 - Create a new document library that everyone has access to - I like to call it 'Scripts' so I know what it is for. Everyone must have read access to this or it will 'break' the library view.

Step 2 - Upload the OpenInNewWindowForView.txt file into the library; once loaded, click on the file to open it - it will open in the browser window to display the text. Copy and save the URL from the browser.

Step 3 - Open the library you want to modify and select the "All Documents" view (actually modifying any view will modify it for all views).

Step 4 - Edit the page - add a Content Editor web part to the top of the page (above the view of documents).

Step 5 - Edit the Content Editor web part and in the "Content Link" of the properties, paste in the URL path you saved in Step 2 and click OK to save.

Step 6 - Stop Editing the page and you are done!

Once the script has been added, if desired, you can save the library as a template but be sure that the script is accessible from any location otherwise it won't work!

NOTE: CHANGE IN BEHAVIOR! Once the Content Editor web part has been added, it 'breaks' the library in that the "Files" and "Library" tab disappear (!). This is easily overcome however:

1) To get to the settings, you can use the Site Contents Page - mouse over the library and click the ellipsis (...) to get to Settings.

2) Simply select any document or folder in the list and the "Files" and "Library" tabs re-appear.