SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do you programmatically add an item to the Pages list from a feature receiver in a sandbox solution?

NB: The Microsoft.Publishing.dll assembly is not available within the sandbox, so you can't use the PublishingWeb class.

In addition, I also want to be able to specify a custom page layout, and make the page the site's default / home page.

share|improve this question

In Sandbox solutions you could always rely on MODULE-s to deploy physical files. You should:

  1. Create a new Module, which deploy in the PAGES library. The trick here is to properly reference the handler for your page, because as oposed to WebPart pages, Publishing pages rely on Page Layouts (you also need to ensure that Page Layout and associated content type is already deployed at Site collection level, prior to attempting page creation). I'd recomand you read Waldek's post but also look in the 14-hive for the Publishing Web feature which has examples in it.
  2. Deploy the module via a Feature (could be Web scoped).
share|improve this answer
Hi C. Marius. I already have modules in my solution which deploy publishing pages to all my new sites, however in this particular case I am creating a feature which needs to delete and recreate the pages of an existing site each time it's deactivated and reactivated. Declarative modules do not support this behaviour (which is confirmed at the bottom of Waldek's post that you linked) -- when a feature containing a module is reactivated, the page is never overwritten, instead multiple copies of the web parts are added to the zones / page. So I'm stuck with using a feature receiver... – Nick Larter Jan 14 '13 at 16:51
If it's all about deleting (and you are sure of it), why don't you simply connect to the PAGES library and delete the item as it would be a Document? – Marius Constantinescu - MVP Jan 15 '13 at 15:13
I've already got the deletions working fine. However in order to provision the pages again AFTER the existing files have been deleted, it needs to be done programmatically in the feature receiver too. I realise I could use two seperate features (one to delete the files programmatically, and a second feature to declaratively reprovision the pages) -- however that seems a little unecessary! – Nick Larter Jan 15 '13 at 15:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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