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

Sathish Nadarajan
Solution Architect
May 11, 2017
Rate this article
[Total: 0    Average: 0/5]

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.

Author Info

Sathish Nadarajan
Solution Architect
Rate this article
[Total: 0    Average: 0/5]
Sathish is a Microsoft MVP for SharePoint (Office Servers and Services) having 13+ years of experience in Microsoft Technologies. He holds a Masters Degree in Computer Aided Design and Business more

Leave a comment