private static void applyTemplate(SiteInformation siteInformation, ExecutionContext functionContext, ClientCredentials credentials, TraceWriter log) { try { using (var ctx = new AuthenticationManager().GetAppOnlyAuthenticatedContext(siteInformation.SiteUrl, credentials.ClientID, credentials.ClientSecret)) { Web web = ctx.Web; ctx.Load(web, w => w.Title, w => w.Navigation.QuickLaunch); ctx.ExecuteQueryRetry(); string groupID = GetSiteGroupID(ctx); // UpdateSubscriptionItemProperties(credentials, siteInformation, web.Title ,log); var rootSiteUrl = ConfigurationManager.AppSettings["RootSiteUrl"]; log.Info($"Successfully connected to site: {web.Title}"); var navigationcolls = web.Navigation.QuickLaunch; foreach (var nav in navigationcolls) { if (nav.Title == "Key Dates & Deliverables") { string url = nav.Url.Split('?')[0] + "?groupId=" + groupID + "&planId=" + siteInformation.PlanId; nav.Url = url; nav.Update(); ctx.ExecuteQueryRetry(); } } string currentDirectory = functionContext.FunctionDirectory; DirectoryInfo dInfo = new DirectoryInfo(currentDirectory); var schemaDir = dInfo.Parent.FullName + "\\Templates"; XMLTemplateProvider sitesProvider = new XMLFileSystemTemplateProvider(schemaDir, ""); log.Info($"About to get template with with filename '{PNP_TEMPLATE_FILE}'"); ProvisioningTemplate template = sitesProvider.GetTemplate(PNP_TEMPLATE_FILE); var getHomeClientPage = template.ClientSidePages.Find(i => i.Title == "Home"); if (getHomeClientPage != null) { UpdateControlsDataDynamic(siteInformation, getHomeClientPage); } log.Info($"Successfully found template with ID '{template.Id}'"); ProvisioningTemplateApplyingInformation ptai = new ProvisioningTemplateApplyingInformation { ProgressDelegate = (message, progress, total) => { log.Info(string.Format("{0:00}/{1:00} - {2}", progress, total, message)); } }; // Associate file connector for assets.. FileSystemConnector connector = new FileSystemConnector(Path.Combine(currentDirectory, "Files"), ""); template.Connector = connector; web.ApplyProvisioningTemplate(template, ptai); if (siteInformation.IsTopNavigation) { // Add top navigation bar. web.AddNavigationNode("SharePoint Main Menu", new Uri(rootSiteUrl + "/SitePages/Home.aspx"), "", OfficeDevPnP.Core.Enums.NavigationType.TopNavigationBar); web.AddNavigationNode("Document Centre", new Uri(rootSiteUrl + "/Document%20Centre/SitePages/Home.aspx"), "", OfficeDevPnP.Core.Enums.NavigationType.TopNavigationBar); web.AddNavigationNode("Project Centre", new Uri(rootSiteUrl + "/Project%20Centre/SitePages/Home.aspx"), "", OfficeDevPnP.Core.Enums.NavigationType.TopNavigationBar); web.AddNavigationNode("WHS Centre", new Uri(rootSiteUrl + "/WHS%20Centre/"), "", OfficeDevPnP.Core.Enums.NavigationType.TopNavigationBar); web.AddNavigationNode("Training Centre", new Uri(rootSiteUrl + "/Training%20Centre"), "", OfficeDevPnP.Core.Enums.NavigationType.TopNavigationBar); web.AddNavigationNode("Proposal Hub", new Uri(rootSiteUrl + "/Proposal%20Hub"), "", OfficeDevPnP.Core.Enums.NavigationType.TopNavigationBar); } UpdateListTitle(ctx, web, "01. Project Management"); } } catch (Exception e) { log.Error("Error when applying PnP template!", e); throw; } }