2

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.

Thanks

4 Answers 4

2

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

1

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

0
  • 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.

2
  • 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 Aug 30, 2010 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, 2010 at 2:40
0

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.

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.