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)
{
ProvisionMasterPagesAndJSFiles();
}
public static void ProvisionMasterPagesAndJSFiles()
{
OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
string siteUrl = "https://*******.sharepoint.com/sites/communitysite";
string userName = "Sathish@*********.onmicrosoft.com";
string password = "************";
string ResourcesDirectory = @"C:SATHISHPRACTICE SOURCE CODESOffice365.ConsoleOffice365.ConsoleResources";
string ResourcesFile = "ProvisioningTemplate.xml";
using (var clientContext = authMgr.GetSharePointOnlineAuthenticatedContextTenant(siteUrl, userName, password))
{
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.ExecuteQueryRetry();
var provisioningProvider = new XMLFileSystemTemplateProvider(ResourcesDirectory, string.Empty);
var provisioningTemplate = provisioningProvider.GetTemplate(ResourcesFile);
provisioningTemplate.Connector.Parameters[FileConnectorBase.CONNECTIONSTRING] = ResourcesDirectory;
clientContext.Web.ApplyProvisioningTemplate(provisioningTemplate);
clientContext.ExecuteQuery();
}
}
}
}
And the Provisioning Template is
<?xml version="1.0"?>
<pnp:ProvisioningTemplate ID="Demo.TeamSite" Version="1" xmlns:pnp="http://schemas.dev.office.com/PnP/2015/12/ProvisioningSchema">
<pnp:Files>
<pnp:File Src="MasterPagesMy.seattle.master" Folder="_catalogs/MasterPage" Overwrite="true" />
<pnp:File Src="JSFilesJavaScript1.JS" Folder="SiteAssetsJS" Overwrite="true" />
</pnp:Files>
</pnp:ProvisioningTemplate>
The Solution will be looks like
Happy Coding,
Sathish Nadarajan.
Leave a comment