Skip to content

Instantly share code, notes, and snippets.

@AsishP
Created August 12, 2018 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsishP/97c139994b78cdfd670fdd7dcb34680f to your computer and use it in GitHub Desktop.
Save AsishP/97c139994b78cdfd670fdd7dcb34680f to your computer and use it in GitHub Desktop.
using (Context ctx = new ClientContext(<siteUrl>))
{
string TemplateFilename = "<FileName>.xml";
ctx.Load(ctx.Web, w => w.Lists, w => w.Folders);
Microsoft.SharePoint.Client.File templateFile = ctx.Web.Lists.GetByTitle("Site Assets").RootFolder.Folders.GetByUrl("Templates").GetFile(TemplateFilename);
ctx.ExecuteQuery();
FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(ctx, templateFile.ServerRelativeUrl);
assetContext.ExecuteQuery();
filePath = Path.GetTempPath() + "\\" + TemplateFilename;
using (var fileStream = new FileStream(filePath, FileMode.Create))
fileInfo.Stream.CopyTo(fileStream);
}
using (FileStream fs = System.IO.File.OpenRead(filePath))
{
ITemplateFormatter formatter = XMLPnPSchemaFormatter.LatestFormatter; //Use the same version as the PnP template
Template = formatter.ToProvisioningTemplate(fs);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment