Forum Discussion
omkar kuchekar
May 19, 2017Copper Contributor
How to export XML from sharepoitn site using PnP provisioning schema.
Hi all,
I am posting some basic info regarding how we can retreive XML from sharepoitn site using PnP provisioning. It helps to start the basic of sharepoint PnP provisioning schema.It might be helpful for all.Let me know any comments.
below C# code for console app.
private static ProvisioningTemplate GetProvisioningTemplate(ConsoleColor defaultForeground, string webUrl, string userName, SecureString pwd)
{
using (var ctx = new ClientContext(webUrl))
{
// ctx.Credentials = new NetworkCredentials(userName, pwd);
ctx.Credentials = new SharePointOnlineCredentials(userName, pwd);
ctx.RequestTimeout = Timeout.Infinite;
// Just to output the site details
Web web = ctx.Web;
ctx.Load(web, w => w.Title);
ctx.ExecuteQueryRetry();
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Your site title is:" + ctx.Web.Title);
Console.ForegroundColor = defaultForeground;
ProvisioningTemplateCreationInformation ptci
= new ProvisioningTemplateCreationInformation(ctx.Web);
// Create FileSystemConnector, so that we can store composed files temporarely somewhere
ptci.FileConnector = new FileSystemConnector(@"c:\temp\pnpprovisioningdemo", "");
//ptci.PersistBrandingFiles = true;
//ptci.PersistPublishingFiles = true;
//ptci.IncludeNativePublishingFiles = true;
ptci.ProgressDelegate = delegate (String message, Int32 progress, Int32 total)
{
// Only to output progress for console UI
Console.WriteLine("{0:00}/{1:00} - {2}", progress, total, message);
};
// Execute actual extraction of the tepmplate
ProvisioningTemplate template = ctx.Web.GetProvisioningTemplate(ptci);
// We can also serialize this template for future usage if we want, not really needed
XMLTemplateProvider provider =
new XMLFileSystemTemplateProvider(@"c:\temp\pnpprovisioningdemo", "");
provider.SaveAs(template, "MyPnPDemo.xml");
return template;
}
}
- Deleted
Why do you not use the Powershell commands?
Connect-PnPOnline -Url $Site -Credential 'nltest'Write-Output "Context obtained";Get-PnPProvisioningTemplate -Force -Out C:\temp\nltest.xml- omkar kuchekarCopper ContributorIts a secure machine so I dont have any software installed so that i am using sharepoint online ans VS2015 to communicate sharepoitn site.Thanks for the info.
Hi omkar kuchekar,
Being a secure machine or not doesn't make sense. If you can run a console app ( that you are building then you could copy the Powershell module folder form a different system.
set $env:PSModulePath to include that folder and PowerShell will pickup your PnP PowerShell. The PowerShell CmdLts don't do anything else than a Console app would do.
If you're just trying to export templates then I would agree with Deleted PnP PowerShell is the easiest option.