Skip to content

Instantly share code, notes, and snippets.

@vgrem
Created November 19, 2013 16:27
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 vgrem/7548106 to your computer and use it in GitHub Desktop.
Save vgrem/7548106 to your computer and use it in GitHub Desktop.
Create Wiki page via CSOM in SharePoint 2010
/// <summary>
/// Create Wiki page via CSOM
/// </summary>
/// <param name="webUrl"></param>
/// <param name="pageName"></param>
/// <param name="pageContent"></param>
public static void CreateWikiPage(string webUrl, string pageName,string pageContent)
{
const string templateRedirectionPageMarkup = "<%@ Page Inherits=\"Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=14.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c\" %> <%@ Reference VirtualPath=\"~TemplatePageUrl\" %> <%@ Reference VirtualPath=\"~masterurl/custom.master\" %>";
using (var ctx = new ClientContext(webUrl))
{
var wikiPages = ctx.Web.Lists.GetByTitle("Pages");
ctx.Load(wikiPages);
ctx.ExecuteQuery();
var file = new FileCreationInformation
{
Url = pageName,
Content = Encoding.UTF8.GetBytes(templateRedirectionPageMarkup),
Overwrite = true
};
var wikiFile = wikiPages.RootFolder.Files.Add(file);
ctx.Load(wikiFile);
ctx.ExecuteQuery();
var wikiPage = wikiFile.ListItemAllFields;
wikiPage["PublishingPageContent"] = pageContent;
wikiPage["PublishingPageLayout"] = "/_catalogs/masterpage/EnterpriseWiki.aspx, Basic Page";
wikiPage.Update();
ctx.ExecuteQuery();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment