public void Execute(ClientContext ctx, string destinationLibrary, string pageName, T wikiTemplate) { Logger.Verbose($"Started executing {nameof(CreateWikiPage)} for page '{pageName}' in library '{destinationLibrary}'"); ctx.Load(ctx.Web); var pages = ctx.Web.Lists.GetByTitle(destinationLibrary); ctx.Load(pages, p => p.RootFolder.ServerRelativeUrl); ctx.ExecuteQuery(); var serverRelativePath = pages.RootFolder.ServerRelativeUrl + "/" + pageName; var candidate = ctx.Web.GetFileByServerRelativeUrl(serverRelativePath); ctx.Load(candidate, f => f.Exists); ctx.ExecuteQuery(); if (candidate.Exists) { Logger.Warning($"Page '{pageName}' already exists"); return; } if (wikiTemplate == T.None) { throw new ArgumentException("Uninitialized wiki template"); } else if (!wikiTemplateContentMapping.ContainsKey(wikiTemplate)) { throw new ArgumentException($"Unsupported wiki template: {wikiTemplate}"); } var newFile = pages.RootFolder.Files.AddTemplateFile( serverRelativePath, TemplateFileType.WikiPage); ctx.Load(newFile, f => f.ListItemAllFields); ctx.ExecuteQuery(); var fields = newFile.ListItemAllFields; fields["WikiField"] = wikiTemplateContentMapping[wikiTemplate]; fields.Update(); ctx.ExecuteQuery(); }
public void Execute(ClientContext ctx, string destinationLibrary, string pageName, T wikiTemplate) { Logger.Verbose($"Started executing {nameof(CreateWikiPage)} for page '{pageName}' in library '{destinationLibrary}'"); ctx.Load(ctx.Web); var pages = ctx.Web.Lists.GetByTitle(destinationLibrary); ctx.Load(pages, p => p.RootFolder.ServerRelativeUrl); ctx.ExecuteQuery(); var serverRelativePath = pages.RootFolder.ServerRelativeUrl + "/" + pageName; var candidate = ctx.Web.GetFileByServerRelativeUrl(serverRelativePath); ctx.Load(candidate, f => f.Exists); ctx.ExecuteQuery(); if (candidate.Exists) { Logger.Warning($"Page '{pageName}' already exists"); return; } if (wikiTemplate == T.None) { throw new ArgumentException("Uninitialized wiki template"); } else if (!wikiTemplateContentMapping.ContainsKey(wikiTemplate)) { throw new ArgumentException($"Unsupported wiki template: {wikiTemplate}"); } var newFile = pages.RootFolder.Files.AddTemplateFile( serverRelativePath, TemplateFileType.WikiPage); ctx.Load(newFile, f => f.ListItemAllFields); ctx.ExecuteQuery(); var fields = newFile.ListItemAllFields; fields["WikiField"] = wikiTemplateContentMapping[wikiTemplate]; fields.Update(); ctx.ExecuteQuery(); }