SandBox solution : provision publishing page with custom web parts


In my last article i talked about provisioning publishing pages with a module on sandboxed solutions.

Today i will talk about adding custom WebParts to a provisioned publishing page.

On farm solutions we need only type of the WebPart and the import error message. But on sandbox we need to specify the id of the solution that deployed the WebPart :







You can find the solution ID on the manifest file of the package.



Sandbox Solution : Provision publishing page

Last year while working with sandboxed solution for SharePoint 2010, i faced a problem while creating a module to provision publishing pages with WebParts.

Problem :

I used this code :






I added this module on a feature, but when i activate the feature i get :

  1. The page is draft
  2. The WebPart is not added.

Solution :

This approach assume that the file “page.aspx” will be copied on the 14 folder on the feature folder. However SandBoxed solutions do not have access to root folder.

The solution is to use a file which is already on the SharePoint root folder :





What i changed is the “SetupPath” , this property is used to specify a physical path to a folder that contains a file to include on the module.

I will use the file “SiteTemplates\SPS\default.aspx” so i set SetupPath to “SiteTemplates\SPS” and the Path of the file to “default.aspx”.

And now everything is working fine 🙂