2

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:

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;
}

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.

I have also tried setting the default content like this:

wikiItem[SPBuiltInFieldId.WikiField] = "my demo content";

But that gives an invalid field error.

I have also tried creating the page with this line of code instead:

SPFile wikiPage = SPUtility.CreateNewWikiPage(wiki, String.Format("{0}/{1}", rootFolder.ServerRelativeUrl, "MyWikiPage.aspx"));

But the result is exactly the same.

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.

Please help.

2 Answers 2

0

Targeting the Pages library in a Enterprise Wiki would not work using the regular Wiki manipulation routines as in the case of Site Pages because this is based on Content Types.

Basically your Pages library is having Enterprise Wiki Page as the default Content type and the easiest way to approach it is to rely on the creating a new Publishing Page instead and update Content type properties accordingly to each of its field types.

See here for an example: http://sharepoint2010mind.blogspot.ch/2012/06/add-publishing-page-to-sharepoint-site.html

0
-1

From all your trials its very much clear that you have already tried all possible approaches. Can you try to use SitePages instead of Pages library. I am sure this will work. Also can you check whether publishing feature was enabled at Site level as well.

1
  • It did stated that he is using "Enteprise Wiki" and Pages library, which is like a Publishing Site. Using Site Pages would not be available in the Enterprise Wiki sites, unless manually created! Oct 30, 2012 at 17:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.