1. I created a empty project
  2. added module
  3. copy onet.xml and default.aspx from layout/template/sts directory to my project and added to my project
  4. Ran F-5 to debug and it seems to be working
  5. Now I need to add some some on feature activation. I added a sample to code to add a list based on type 100 (object model , c#)
  6. After creating a site (web to be exact) I dont see the sample list that I asked feature activation to create.

What am I doing wrong? (Its a sandbox solution)

4 Answers 4


I experienced a similar issue. Upon creation of a new site, the features included in the <WebFeatures> node of the ONet.xml were not activated upon site creation. When navigating to '/_layouts/ManageFeatures.aspx' these features would appear to be activated but their code would not run (no files were placed from modules, breakpoints set in event receivers would not be reached). I was able to resolve the issue by making a change in my Feature nodes. Originally the nodes I used were copied from an ONET extracted from a .wsp that had been generated using the 'Save Site as Template' feature. Those nodes looked like this:

<Feature ID="{5bd39d1e-9e39-4e4f-932c-eb393b5454a4}" Name="FeatureDefinition/5bd39d1e-9e39-4e4f-932c-eb393b5454a4" SourceVersion=" />

When I modified the Node to resemble this:

<Feature ID="{5bd39d1e-9e39-4e4f-932c-eb393b5454a4}" />

The features activated as expected.

  • I don't know why it works that way, but making this change actually made our feature receiver to be called.
    – jjczopek
    Feb 21, 2015 at 11:11

Hmm just to be clear, you cannot create custom site definitions as sandboxed solutions. If this must be a sandboxed solution you should instead create a custom web template. Read thhis guide by Vesa

  • @Anders: I am doing custom web template. Basically, I want to run some code when a sub-site is provisioned based on this template. I put the code on featureactivated event of the site feature and it did not fire when I create a sub-site. I then added another feature within the same project and scoped to web and put the event receiver code on feature's activated area. Still does not work (i also put feature activation code in the onet.xml file). I need to create few list using object model when a sub site is create. What are my options?
    – Roxanne
    May 8, 2011 at 18:10
  • Ok but you wrote "custom site definition", and thats something else entirely ;-) Site features are not activated when webs are created. In SP2007 they did, but that was a bug that is now fixed in SP2010. If the web scoped feature isnt activated when creating sub sites, you need to check for reasons for this in ULS log. Also check that your solutions are deployed without errors Get-SPSolution | Select-Object Name, LastOperationResult or check in CA. You write you put your feature in feature's activated area AND onet.xml. Not sure what you mean by that. You cannot staple features on web templ. May 8, 2011 at 22:06
  • To validate if your code is called or not, set a breakpoint in feature activated and attach worker process in Visual Studio. If breakpoint isnt hit, either feature isnt provisioned correctly (check in activated features for web) or code isnt updated in GAC. To fix this either do a full redeploy or use CKS:DEV to copy dll to GAC May 8, 2011 at 22:08
  • As wictor mentioned on your new Q, check that feature is added to the relevant scope. Web scoped goes in WebTemplates, site scoped goes in SiteTemplates May 9, 2011 at 6:22
  • @Anders: Yes sir I did put the feature that is scoped to web under the webTemplate section of the onet.xml file. I get an error when I do that. (The site template requires that the Feature [GUID] be installed in the farm or site collection. Unfortunately it's not possible to use Feature Stapling with Web Templates in SharePoint 2010.
    – Roxanne
    May 9, 2011 at 10:56

If you added the code in a Feature Receiver, you need that Feature to be avtivated upon site creation.

Thus, you need to add an element inside the ONET.xml which references your Feature. Have a look and you'll see the other features there, referenced with GUIDs.

You need to find the GUID your feature has been assigned within visual studio, then add that GUID to the list of Feature Activations within the ONET.

  • Thank you james. Is it going in the site template block of the onet.xml?
    – Roxanne
    May 8, 2011 at 0:07
  • 1. I added reference to onet.xml for the feature 2. My feature is at site coll. level so it's failing when I provision a web What are my options?
    – Roxanne
    May 8, 2011 at 0:12
  • I added a second feature so I can target this feature for web, scope == web. but when I change the scope to web it also changes the other feature's scope to web. Damn it. I am so hating SP.
    – Roxanne
    May 8, 2011 at 0:29
  • You'll need any and all features to be web scoped in a Web Template.
    – James Love
    May 9, 2011 at 7:31
  • @James: Are you sure about all features to be web scoped. I download Vesa's article solution where he added 4 features and each is scope to different (farm, sc, web, etc.). blogs.msdn.com/b/vesku/archive/2010/10/14/…
    – Roxanne
    May 9, 2011 at 11:00

I had to add a event handler and I choose webprovisioned event handler.

  • 1
    Roxanne - do you have any articles discussing this please? Facing the same problem as you in your OP - still can't suss it out. Sep 24, 2012 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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