title: How to programmatically create editable wiki pages within the Pages library of an Enterprise Wiki site
body: <p>I'm new to SharePoint. I'm trying to programmatically create a wiki page within the Pages library of an Enterprise Wiki site in SharePoint 2010. Here is my code:</p>
  
  <pre><code>using (SPSite site = new SPSite(SPContext.Current.Web.Url))
  {
          SPWeb rootWeb = site.RootWeb;
          rootWeb.AllowUnsafeUpdates = true;
          SPList wiki = rootWeb.Lists["Pages"];
          SPFolder rootFolder = wiki.RootFolder;
          SPFile wikiPage = rootFolder.Files.Add(String.Format("{0}/{1}", rootFolder.ServerRelativeUrl, "MyWikiPage.aspx"), SPTemplateFileType.WikiPage);
          SPListItem wikiItem = wikiPage.Item;
          wikiItem["PublishingPageContent"] = "my demo content";
          wikiItem.UpdateOverwriteVersion();
          rootWeb.AllowUnsafeUpdates = false;
  }
  </code></pre>
  
  <p>The page gets created but the problem is that the created page is not editable and the demo content is not inserted. When opened in edit mode, no content space is available and edit options are greyed out.</p>
  
  <p>I have also tried setting the default content like this:</p>
  
  <pre>    wikiItem[SPBuiltInFieldId.WikiField] = "my demo content";</pre>
  
  <p>But that gives an invalid field error.</p>
  
  <p>I have also tried creating the page with this line of code instead:</p>
  
  <pre>    SPFile wikiPage = SPUtility.CreateNewWikiPage(wiki, String.Format("{0}/{1}", rootFolder.ServerRelativeUrl, "MyWikiPage.aspx"));</pre>
  
  <p>But the result is exactly the same.</p>
  
  <p>I have confirmed that "SharePoint Server Publishing" feature is turned on for the site and "SharePoint Server Publishing Infrastructure" feature is turned on for the site collection.</p>
  
  <p>Please help.</p>