Create New Site from Custom Web Template in Office 365 (SharePoint Online)

This week I am working for a customer who wants to develop a new solution that will allow users to create new SharePoint Online sites, based on a custom web Template, with a single click. After struggling for a few hours trying to find the proper way of achieving this using the SharePoint add-in model, I came up with a very simple solution that allows a user to automate the creation of SharePoint Online sites based on a custom web Template, using calls to the REST API.

We are all familiar with the default out-of-the-box templates (ex: STS#0), but custom web templates are a little different. The first thing you need to know when dealing with custom web templates, is that every one of them are provided a custom ID based on the following naming convention: <GUID>#<Template Name>. For example, assume you were to create a new site template and give it a title of “MasterTemplate”, the given Name for your Template could end up being something like “{2AA91D04-377B-431A-8D23-7424893F5CEB}#MasterTemplate”. The first part of the ID (before the ‘#’) is what we will need to pass to the REST method responsible for creating our new web.

Solution Overview

The solution we will be studying here is made up of two components. The first one will help us retrieve the actual ID of our custom Web Template. The second will be used to actually create the new site, using the retrieved custom Template. All of this will be achieved using a SharePoint-Hosted Add-In and by making REST calls using JavaScript.

For the purpose of this article, I went ahead in SharePoint Online and created a new site, which I’ve modified a bit so that it can be re-used over and over as a Template. I’ve cleaned all web parts from the landing page, and created two custom lists: a task list named “Team Tasks”, and an issue list named “Team Issues to Track”.

I then went ahead and saved this site as a Template. If you don’t see this option in your site settings, make sure you have Scripting enabled for the given site collection (more info at I named my Template (Help Desk Case).

Now that our custom Web Template is created and registered in our SharePoint Online Site Collection, we need to figure out what its ID is. To achieve this, I went ahead, opened Visual Studio, and created a new SharePoint Add-In. We will be using this Add-In to retrieve the ID of all of our existing Site Templates (including the custom ones), and display them to our users in a drop down list. The idea here is to query tthe following REST endpoint:
/_api/web/getavailablewebtemplates(lcid=1033, doincludecrosslanguage=true)

In the add-in default.aspx page, I have created a new empty DIV element with an ID of “divMain”. This empty div will be used to dynamically generate our drop down list of values contining information about all the available Web Templates. What our JavaScript code will do, is query the host web to retrieve the list of all available Web Templates, loop through each of them and add it to our dynamically generated Drop Down list. The option items in our drop down list will display the Title of each Web Template, but will have a value representing their internal ID.


The code used in the App.js file for our add-in to retrieve that list is the following:

'use strict';

ExecuteOrDelayUntilScriptLoaded(initializePage, "sp.js");

function initializePage()
var hostweburl;
var appweburl;

// This code runs when the DOM is ready and creates a context object which is needed to use the SharePoint object model
$(document).ready(function () {
hostweburl = decodeURIComponent($.getUrlVar("SPHostUrl"));
appweburl = decodeURIComponent($.getUrlVar("SPAppWebUrl"));
var scriptbase = hostweburl + "/_layouts/15/";

// load the executor script, once completed set the ready variable to true so that
$.getScript(scriptbase + "SP.Runtime.js",
function () {
$.getScript(scriptbase + "SP.js",
function () { $.getScript(scriptbase + "SP.RequestExecutor.js", getWebTemplates); }
function getWebTemplates()
var requestURL = appweburl + "/_api/SP.AppContextSite(@target)/web/getavailablewebtemplates(lcid=1033, doincludecrosslanguage=true)?@target='" + hostweburl + "'";
var executor = new SP.RequestExecutor(appweburl);

url: requestURL,
type: "GET",
headers: {
"accept": "application/json;odata=verbose"
success: function (data) {
var jsonObject = JSON.parse(data.body);
var results = jsonObject.d.results;
var s = $('<select id="ddlTemplate" />');
for(var i = 0; i < results.length; i++) { $('<option />', { value: results[i].Name, text: results[i].Title }).appendTo(s); } s.appendTo('#divMain'); }, error: function (xhr, status, error) { alert(JSON.stringify(xhr)); } }); } } jQuery.extend({ getUrlVars: function () { var vars = [], hash; var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); for (var i = 0; i < hashes.length; i++) { hash = hashes[i].split('='); vars.push(hash[0]); vars[hash[0]] = hash[1]; } return vars; }, getUrlVar: function (name) { return jQuery.getUrlVars()[name]; } });

Now that we managed to retrieve all site templates for our SharePoint Online Site Collection, we need to work on the piece of our Add-in's code that will actually go and create the site based on the web Template we've selected from our drop down list. To achieve this, we will modify the default.aspx page of our Add-in to include a text box allowing the users to enter a title for their new site, and a button to initiate the site's creation. The default.aspx code for my solution looks like the following:

<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">

<strong>Title: </strong><input type="text" id="siteTitle" /><br />
<strong>Site Template: </strong>
<div id="divMain">

<input type="button" id="btnCreate" value ="Create Site" onclick="createSite" />


Now that the visuals are in place, we actually need to connect our button to the action that will create the new site. Based on the .NET markup above, we can see that my button is trying to call a JavaScript function named "createSite". One very important thing: When calling the REST API to initiate the creation of the new site, you should only pass the associated Web Template ID's prefix (what is before the '#' sign). For example, in my case, the ID of my Help Desk Case web template is In order to have the onClick event trigger, we need to add the following logic in our App.js file:

function createSite() {
var requestURL = appweburl + "/_api/SP.AppContextSite(@target)/web/webinfos/Add?@target='" + hostweburl + "'";
var siteTitle = $('#siteTitle').val();
var siteUrl = $('#siteTitle').val().replace(" ", "");
var templateID = $("#ddlTemplate").val().split('#')[0];
var jsonData = "{ 'parameters': { '__metadata': { 'type': 'SP.WebInfoCreationInformation' }, 'Title': '" + siteTitle + "', 'Url': '" + siteUrl + "', 'WebTemplate': '" + templateID + "'} }";

url: requestURL,
type: "POST",
data: jsonData,
headers: {
"accept": "application/json;odata=verbose",
"content-type": "application/json;odata=verbose",
"X-RequestDigest": $('#__REQUESTDIGEST').val()
success: function () { alert("site Created"); },
error: function (xhr, status, error) {

Let's now compile and deploy our add-in. the user running your add-in should now be presented with a form similar to the picutre below, allowing them to select both out-of-the-box and custom web templates in SharePoint Online, and create new sites with a simple click. Once the site has been successfully created, the user will get a prompt. Off course there is a lot of validation stuff you should take care off yourself if you'd ever want to implement such a solution into production (check that URL doesn't have characters, etc.).
My Case 1

You can get a copy of the files used in this article Here

Installing Office Online Server for SharePoint 2016

Office Online Server is the next version of the Office Web Apps, which allows your users to view and edit Microsoft Office documents directly in their browsers. It is also a prerequisite to have the Durable Links feature of SharePoint 2016 on-premises work properly. Just like its 2013 predecessor, Office Online Server 2016 needs to be installed on its own server, and cannot coexist with a SharePoint installation. It can still be used as a standalone installation.

In the present article, I will go over the installation process. The farm I will use is a SharePoint 2016 farm hosted in Azure. It has one SQL Server with the SharePoint 2016 Application Server MinRole installed on, a Web-Front end (MinRole), and a standalone Office Online Server (OOS) node.

In this article, we will be installing Office Online Server on an Azure server named AzureSPOOPS (not an typo, the ‘p’ was there for -on-premises). The server is running Windows Server 2012 R2 and is a brand new Azure Cloud Virtual Machine I just created. If you simply try to run the setupe.exe application from the installation media on a new server, you will get the following error. Please note that this article was written at a time when the Office Online Server had just been made available for 3 days, so installation steps and screens are likely to change once the product its RTM.



As the error message states, we need to first start an enable the Web-Server role on the server in order for the installation to work. This can be done two ways:

1 – Using the Graphical User Interface:

a) Launch Server Manager and click on Manage > Add Roles and Features


b) Click Next on the first screen


c) Keep the default Role-based or feature-based installation option selected, and click Next


d) Keep the option Select a server from the server pool selected, making sure that the local server in selected in the Server Pool list, and click Next


e) On the Select server roles screen, scroll down to the bottom of the list, and check Web Server (IIS). Click Next


f) A prompt will appear, simply click on the Add Features button


g) On the Select features screen, select Ink and Handwriting Services then click on Next


h) On the Web Server Role (IIS) screen, simply click NextAddFeatures-Screen7

i) On the Select role services screen, keep the default options selected and click NextAddFeatures-Screen8

j) On the Confirm installation selections screen, click on the Install button


Let the installation progress finish and close the window.

2) Use PowerShell:

Using PowerShell, the Web-Server role can be enabled by simply calling the following line of code:

Install-WindowsFeature -Name Web-Server,InkAndHandWritingServices -IncludeAllSubFeature -ComputerName &lt;<em>Computer Name</em>&gt;


After a minute or two, the role should be activated and the following output should be shown in the PowerShell console:


We are now ready to re-run the setup.exe installation application for the Office Online Server. This time, instead of getting the error message, we should be presented with the License Terms screen (yes, the title says Microsoft Office Online Server 2013, which in theory never existed). Click I accept the terms of this agreement and click on the Continue button.


Keep the default installation path, unless you have a requirement to put the files in a separate location (e.g. different disk drive). Click on the Install Now button.


Wait for the installation progress to finish


The installation progress should take about 5-6 minutes. Once completed, you will be presented with the following screen. Simply click on the Close button.


Creating the Office Online Farm:

After installing the Office Online Server 2016 bits, in order for the product to be usable, we need to configure a new “Farm”. This is achieved with PowerShell, using the following lines of code. Launch a new PowerShell console running as administrator and simply replace the URL with yours:

Import-Module OfficeWebApp
New-OfficeWebAppsFarm -InternalUrl "<span style="font-family: Courier New;">&lt;<em>HTTPS Url</em>&gt;</span>" -ExternalUrl "&lt;<em>HTTPS Url</em>&gt;" -SSLOffloaded –EditingEnabled

*Note SSLOffloaded should only be used in dev/test environments. In production you will want to have the communication done over SSL.

When prompted to turn setting EditingEnabled to TRUE, enter Y. Once completed, the following screen will be shown:


At this point, our job is done for the Office Online Server 2016 configuration. You can go ahead and test that the “Farm” was successfully created by trying to access http://<server name>/hosting/discovery using Internet Explorer (or edge if using Windows Server 2016 Preview). If everything worked, you should see the server’s XML WOPI output as shown in the figure below:


Connecting SharePoint 2016:

Now that the Office Online Server 2016 bits have been installed, the next step is to actually tell our SharePoint 2016 farm about the existence of this new server. In order to do this, launch a new SharePoint Management Shell console on one of the SharePoint 2016 server. What we need to do now is declare a new WOPI binding on the SharePoint server to tell it about the existence of the new Office Online Server 2016 farm. This is done by executing the following line of PowerShell:

New-SPWOPIBinding -ServerName &lt;servername&gt; -AllowHTTP

*Note that -AllowHTTP is ok for non-production environments only. In a production environment you’ll want to ensure communication is done over SSL.

If the command worked, you will see a lot of Office specific properties being output on screen


We are now all set!

SharePoint 2016 – Share Documents with QR Codes

A new feature has been introduced in SharePoint 2016 IT Preview that allows users to share documents using QR codes. By default, each documents library has this feature enabled. Simply upload a document to a document library, and using the document properties overlay, you can generate a QR code for the document.

SharePoint 2016 QR Code

Clicking this icon will automatically bring the user over to a new application page (/_layouts/15/qr.aspx) which will generate a QR code.

SharePoint 2016 Generated QR Code for a document

My Microsoft Virtual Academy Session on Office 365 Development

I just realized that I never truly advertised on my blog the session I delivered back in March 2015 for the Microsoft Virtual Academy in Redmond, on Office 365 Development. This full day session was recorded live on March 24th, with my co-host Christopher Harrison. We had a blast! The audience asked several great questions throughout the day. Topics covered included OAuth for the new SharePoint Online Add-In model (still apps at the time), Office 365 apps development, as well as an overview of Azure authentication for your Office 365 apps. You can go ahead and listen to my awesome French Canadian accent right now, and learn all about apps and SharePoint add-ins in Office 365 by going to:

SharePoint 2016 – Fast Site Creation

SharePoint 2016 IT Preview introduces a new feature called Fast Site Creation, which allows SharePoint administrators to quickly create site collections based on an existing template. This feature works at the SQL Server level, meaning that it simply copies artefacts in the SQL server directly without going through the SharePoint Object Model, thus generating multiple round trips back and forth between the SharePoint Servers and the SQL database in the back-end. Currently this feature is only available via PowerShell (which is good for us). I have no insights as to whether or not Microsoft is planning on adding a graphical interface component to Central Administration to allow us to interact with this feature.

From a PowerShell perspective, 6 new cmdlets have been introduced to help us manage the fast site creation feature:


In this article we will go over what every single cmdlet listed above does.


This cmdlet lists all Site Collection Templates that are “Fast Creation Enabled”:

Fast Site Creation SharePoint 2016


This cmdlet disables a site collection template that was “Fast Site Creation Enabled”. In the example below, we disable the STS#0 template:



“Fast Site Creation Enables” a template. For example, after diasbling Fast Site Creation on template STS#0 above, if we wish to re-enable it, we need to run the following cmdlet:



Now that we have our Site Collection templates ready for Fast Site Creation, we need to create what we call a new Site Master. Think of a Site Master has being a cookie cutter. It is a blank “mould” from which all site collections created via Fast Site Creation will be made from. They will actually be a copy of that blank site master.



Returns a reference to the Site Master associated with a content database:



You probably have guessed by now what that cmdlet does. Yeah, that’s right, it deletes a Site Master from a content database:


Now that we’ve looked at all the PowerShell cmdlets involved in SharePoint 2016’s Fast Site Creation, let’s see it in action. In order for us to create a new site collection using Fast Site Creation, all we have to do is call the New-SPSite cmdlet we all know and love, but this time we must make our call passing the new -CreateFromSiteMaster parameter:

New-SPSite http://localhost/sites/FSC1 -Template STS#0 -CreateFromSiteMaster -ContentDatabase "WSS_Content" -OwnerAlias "Contoso\administrator"


Ok, it’s not that impressive when you simply look at the outcome. It just creates a new site collection, so what right? What if I told you the creation process was about twice as fast using the Fast Site Creation method? While you may not care for a small SharePoint instance, imagine a large scale SharePoint instance (like Office 365) where you have to spin off hundreds of new site collections a day. Now it is starting to make sense.

Let us now compare the Fast Site Creation with the traditional method in terms of performance. Using the Measure-Command{} PowerShell method, we can compare the time it takes to create a new site collection using the SharePoint 2013 way versus how long it takes doing it the SharePoint 2016 (Fast Site Creation) way.


Measure-Command{New-SPSite http://localhost/sites/FSC2 -Template STS#0 -ContentDatabase “WSS_Content” -OwnerAlias “Contoso\administrator”}


Fast Site Creation (SharePoint 2016):

Measure-Command{New-SPSite http://localhost/sites/FSC3 -Template STS#0 -ContentDatabase “WSS_Content” -OwnerAlias “Contoso\administrator” -CreateFromSiteMaster}


Now you finally understand why this new way of creating site collections is so amazing!