How do I programatically add an article page to a sharepoint site?

Posted by soniiic on Stack Overflow See other posts from Stack Overflow or by soniiic
Published on 2010-02-18T10:30:08Z Indexed on 2010/04/20 13:23 UTC
Read the original article Hit count: 316

I've been given the task of content migration from another CMS system to SharePoint 2010.

The data in the old system is fairly easy to capture and the page hierarchy is simple so I'm not worried about that.

However, I am completely flummoxed about how to even create a page in code. I'm using the Microsoft.SharePoint.Client namespace as I do not have sharepoint installed on my system and am wanting to code this up as a console application and so I'm using I'm using ClientContext. (On the other hand, I am willing to go into other solutions if necessary).

My end-game: To get a page uploaded into some folder hierarchy which uses a master page, has the page title in a header web part, and a big ol' content-editable web part in the body so any user can come along and edit the content.

Things I've tried so far:

  • Using FileCollection.Add() to add an aspx file to the folder "Site Pages". This renders the html in the browser but doesn't enable any features for the user to edit the page
  • Using ListItemCollection.Add() to add a page to the site, but I didn't know what fields I needed. Also I remember it came up with a runtime error saying I should use FileCollection.Add()
  • Uploading to 'Site Pages' instead of 'Pages'
  • So many others... ow my head :(

The only plausible thing I can see on the net is to use the PublishingPage type along with PublishingWeb. However, PublishingWeb can only be constructed from an SPWeb object which requires me to be actually hosting the sharepoint application on my workstation.

If anyone can lend a hand that would be greatly appreciated :)

© Stack Overflow or respective owner

Related posts about sharepoint

Related posts about c#