Friday, October 25, 2013

Sandbox: Creating pages from XML file

Introduction

We are researching a move from SharePoint 2007 to SharePoint Online. Regarding moving the actual content (publishing pages) options seems to be limited especially with regard to migrating towards using managed metadata columns. So what we wanted is the ability to read from an XML file and create publishing pages through sandboxed code. The sandboxed code can be deployed to SharePoint online and the xml can be created by custom farm-level code on the SharePoint 2007 farm.

Solution

The blog article Publishing in sandboxed solutions - Create a page contains the main code behind the sandboxed visual webpart that I created. The webpart depends on a pages.xml file that is the only file in the SiteCollectionDocuments folder (hey, this is only a Proof of Concept!). See below for the contents of the XML file and the code for the webpart.

I used the Visual webpart template in VS2012, set to sandbox solution for developing the webpart. This should work similarly in VS2010 with the Power tools extension installed.

Here's what to do once you have the solution available:

1. Put pages.xml as the only file in the SiteCollectionDocuments folder of a publishing portal
2. Deploy sandboxed solution to site
3. Put CreatePages webpart on a webpart page
4. Push the button and see if a page is created correctly in the Pages library of the root web


Code for Creating Pages from XML file in Sandboxed webpart
XML file from creating pages in sandboxed webpart.

Post a comment if you would like to receive the whole VS project (but hopefully you can build it yourself from this blogpost!)

No comments:

Post a Comment