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 am building a MOSS2010 app. I want to make a custom site definition, which, in itself, will have sites (So it'll be like a site collection which I really want). I want to do this preferably via C# only.

What would be the best way? It seems like site definitions are not up for this.


share|improve this question
up vote 2 down vote accepted

If your site hierarchy is already known at design time, you could implement in the web UI, then save it as a Site Template.

share|improve this answer

An easy way to do this is to use the OOB site provisioning provider that BLANKINTERNET uses (see example of this in stswebtemp.xml and accompaning site hierarchy manifest file).

An alternative is to use a custom provisioning provider in which you programmatically create sub sites (preferably in an XML file). Reuse the provisioning provider in the web template for the sub sites for creating hierarchies.

sharepoint provisioning provider

Another option is to use PowerShell. Define an XML structure that defines webs/subwebs (reuse the structure of the OOB provisioning provider if u like) and iterate it while creating New-SPWeb

share|improve this answer
  • You can scope your site definition to only create site at Root of site collection (via webtemp.xnl file).

  • You can create a stapler feature that associates your site definition with another feature say X. Further you can write a feature receiver class for feature X where in using the Feature Activated event you can use the SharePoint object model and create the required sub sites in your site collection.

share|improve this answer
The problem with this approach is, that stapled features are prone to race conditions due to the random order they are executed (per scope). In other words you have no guarantee that the site currently being provisioned has finished. This is where custom provisioning providers are really strong. I had hoped this would be adressed in SP2010 by the new WebProvisioned event, but since this event is triggered by the root site, it is only usable for creating sub webs – Anders Rask Aug 30 '10 at 8:29
Agreed Anders. We had faced this issue in one of our earlier projects. But we figured out the solution by activating all the other child features (e.g. feature to create child sites) through our stapler feature. Also as you mentioned the issue with site not being provisioned completely: its mainly the style library and the site collection images library that are being provisioned at the last stage. So we kept the branding WSP at the last stage of the deployment and it works like a charm! – Vivek Aug 31 '10 at 2:40

Although I haven't tried it myself, I believe it's possible to leverage the "PortalProvisioningProvider" class which is used by some of SharePoint's default site definitions. This class reads a separate XML file describing the subsite hierarchy. See here for details.

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.