Provision Master Pages and the other files in SharePoint Office 365 using Patterns and Practice C# CSOM

Sathish Nadarajan
SharePoint MVP
Published On :   11 May 2017
Visit Count
Today :  3    Total :   2039

Some time back, we saw how to provision the site columns and content types in an OLD article. But, along with that, we can upload the Master Pages, CSS, JS files to the SharePoint Site as part of provisioning. In this, the same piece of code, with the updated Provisioning XML is shown below.

 using Microsoft.SharePoint.Client;
 using OfficeDevPnP.Core.Framework.Provisioning.Connectors;
 using OfficeDevPnP.Core.Framework.Provisioning.Providers.Xml;
 namespace Office365.Console
     class Program
         static void Main(string[] args)
         public static void ProvisionMasterPagesAndJSFiles()
             OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
             string siteUrl = "https://*******";
             string userName = "Sathish@*********";
             string password = "************";
             string ResourcesDirectory = @"C:\SATHISH\PRACTICE SOURCE CODES\Office365.Console\Office365.Console\Resources";
             string ResourcesFile = "ProvisioningTemplate.xml";
             using (var clientContext = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
                 Web web = clientContext.Web;
                 var provisioningProvider = new XMLFileSystemTemplateProvider(ResourcesDirectory, string.Empty);
                 var provisioningTemplate = provisioningProvider.GetTemplate(ResourcesFile);
                 provisioningTemplate.Connector.Parameters[FileConnectorBase.CONNECTIONSTRING] = ResourcesDirectory;

And the Provisioning Template is

 <?xml version="1.0"?>
 <pnp:ProvisioningTemplate ID="Demo.TeamSite" Version="1" xmlns:pnp="">
     <pnp:File Src="MasterPages\My.seattle.master" Folder="_catalogs/MasterPage" Overwrite="true" />
      <pnp:File Src="JSFiles\JavaScript1.JS" Folder="SiteAssets\JS" Overwrite="true" />

The Solution will be looks like


Happy Coding,

Sathish Nadarajan.