public void XMLFileSystemGetTemplatesTest() { XMLTemplateProvider provider = new XMLFileSystemTemplateProvider( String.Format(@"{0}\..\..\Resources", AppDomain.CurrentDomain.BaseDirectory), "Templates"); var result = provider.GetTemplates(); Assert.IsTrue(result.Count == 6); Assert.IsTrue(result[0].Files.Count == 5); Assert.IsTrue(result[1].Files.Count == 5); Assert.IsTrue(result[2].Files.Count == 1); Assert.IsTrue(result[3].Files.Count == 5); Assert.IsTrue(result[4].Files.Count == 1); Assert.IsTrue(result[5].Files.Count == 5); }
static void Main(string[] args) { bool interactiveLogin = true; string templateSiteUrl = "https://bertonline.sharepoint.com/sites/130049"; string targetSiteUrl = "https://bertonline.sharepoint.com/sites/pr1"; // Office 365: [email protected] // OnPrem: DOMAIN\Username string loginId = "*****@*****.**"; // Get pwd from environment variable, so that we do to need to show that. string pwd = ""; if (interactiveLogin) { pwd = GetInput("Password", true); } else { pwd = Environment.GetEnvironmentVariable("MSOPWD", EnvironmentVariableTarget.User); } if (string.IsNullOrEmpty(pwd)) { Console.WriteLine("MSOPWD user environment variable empty or no password was specified, cannot continue. Press any key to abort."); Console.ReadKey(); return; } // Template ProvisioningTemplate template; // Get access to source site using (var ctx = new ClientContext(templateSiteUrl)) { //Provide count and pwd for connecting to the source ctx.Credentials = GetCredentials(targetSiteUrl, loginId, pwd); // Get template from existing site template = ctx.Web.GetProvisioningTemplate(); } // Save template using XML provider XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(@"c:\temp\pnpprovisioningdemo", ""); string templateName = "template.xml"; provider.SaveAs(template, templateName); // Load the saved model again ProvisioningTemplate p2 = provider.GetTemplate(templateName); // Get the available, valid templates var templates = provider.GetTemplates(); foreach (var template1 in templates) { Console.WriteLine("Found template with ID {0}", template1.Id); } // Get access to target site and apply template using (var ctx = new ClientContext(targetSiteUrl)) { //Provide count and pwd for connecting to the source ctx.Credentials = GetCredentials(targetSiteUrl, loginId, pwd); // Apply template to existing site ctx.Web.ApplyProvisioningTemplate(template); } }
static void Main(string[] args) { bool interactiveLogin = true; string templateSiteUrl = "https://mbakirov367.sharepoint.com/sites/demo4"; string targetSiteUrl = "https://mbakirov367.sharepoint.com/sites/demo4f"; string loginId = "*****@*****.**"; // Get pwd from environment variable, so that we do to need to show that. string pwd = ""; if (interactiveLogin) { pwd = GetInput("Password", true); } else { pwd = System.Environment.GetEnvironmentVariable("MSOPWD", EnvironmentVariableTarget.User); } if (string.IsNullOrEmpty(pwd)) { System.Console.WriteLine("MSOPWD user environment variable empty or no password was specified, cannot continue. Press any key to abort."); System.Console.ReadKey(); return; } // Template ProvisioningTemplate template; // Get access to source site using (var ctx = new ClientContext(templateSiteUrl)) { //Provide count and pwd for connecting to the source var passWord = new SecureString(); foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c); ctx.Credentials = new SharePointOnlineCredentials(loginId, passWord); // Get template from existing site template = ctx.Web.GetProvisioningTemplate(); } // Save template using XML provider XMLFileSystemTemplateProvider provider = new XMLFileSystemTemplateProvider(@"c:\temp\pnpprovisioningdemo", ""); string templateName = "template.xml"; provider.SaveAs(template, templateName); // Load the saved model again ProvisioningTemplate p2 = provider.GetTemplate(templateName); // Get the available, valid templates var templates = provider.GetTemplates(); foreach(var template1 in templates) { Console.WriteLine("Found template with ID {0}", template1.Id); } // Get access to target site and apply template using (var ctx = new ClientContext(targetSiteUrl)) { //Provide count and pwd for connecting to the source var passWord = new SecureString(); foreach (char c in pwd.ToCharArray()) passWord.AppendChar(c); ctx.Credentials = new SharePointOnlineCredentials(loginId, passWord); // Apply template to existing site ctx.Web.ApplyProvisioningTemplate(template); } }