Tuesday, November 5, 2013

Sandbox: Create subsites from XML

Introduction

Last blog entry I talked about creating publishing pages from an xml file in a sandboxed solution. This time I'm continuing in line with an article about creating subsites based on an xml file in the SiteCollectionsDocuments folder. The code is somewhat simpler since creating subsites in the sandbox is not very difficult, it actually works the same as always.

The most difficult part is to run through the XML recursively since you'll want to be able to create sub-sub-sites in your site collection from one input file.

In the xml-file you detail the url, title, description and the webtemplate name you want to use for a node. You could extend this with the future-webs' LCID.
For the webtemplate you can of course also use a custom solution webtemplate that is deployed to the solution gallery, or the name of a site saved as a template (it will then also end up in the solutions gallery).

The webpart consists of only a button (to run the code) and a label (to display errors). You might see an timeout error when running the code. Since creating websites is a time consuming task, I'm pretty certain the following exception occurs:
Have fun trying it out! I was just as lazy as the last time so the code now expects the xml file to be exactly the second file in the SiteCollectionDocuments folder :-)

2 comments: