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

I have created a web template in visual studio, it includes the standard element file and onet file, it also has a feature which is scoped to site level.

All this works fine, i can deploy it and can create a subsite based of this template.

I now want to add some code that creates lists etc when the sub site is created (lists are for sub site only).

How would i do this? I have tried adding another feature to the project which is scoped to web and putting code in this but i get the following error:

"Error occurred in deployment step 'Activate Features': Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred."

share|improve this question
up vote 0 down vote accepted

It looks like you use a sandbox solution to solve you issue. But I don't undestand how can it be, because you can not creaate web template as sandbox. I think that you created another project that is contains a new feature. if it is ture, you should select this project and set sandboxed solution property to false in properties window.

share|improve this answer

Try the SPWebEventReceiver class. This event should fire when a web is created.

public class WebProvisionedEventReceiver : SPWebEventReceiver
    public override void WebProvisioned(SPWebEventProperties properties) 
            using (SPWeb web = (SPWeb)properties.Web)
share|improve this answer

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.