Sharepoint publishing

This blog entry shows a simple example of programmatic page creation in Sharepoint. To do this you need to activate the publishing infrastructure for the site collection and the publishing feature for the site you want to create pages for.

The following example shows the code to add a page called test.aspx and fill it’s fields ‘Image’ (type Image) and ‘Content’ (type HTML).

To use the diffent content types such as Image you need to import the namespace Microsoft.SharePoint.Publishing.Fields and locate the appropriate class. For the Image column you want to use an ImageFieldValue instance.

After creation the page is checked-in, published and approved. Note the try/finally block to make sure that the resources are disposed.

Leave a Reply

Your email address will not be published. Required fields are marked *