Created
November 19, 2013 16:27
-
-
Save vgrem/7548106 to your computer and use it in GitHub Desktop.
Create Wiki page via CSOM in SharePoint 2010
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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