Overwriting SPWebProvisioningProvider.Provision

Imaging you are using own code to overwrite the Provision method.

To prevent possible problems later you should use the following example in your own code.

Example Code Fragment:

public override void Provision(SPWebProvisioningProperties properties)

    string template = properties.Data; //data passed in from WEBTEMP...xml file
    // at this point SharePoint has already created a basic site

    SPWeb web = properties.Web;

    //string WebURL = web.Url;  // the FULL Url
    string RelUrl = web.ServerRelativeUrl; // ServerRelativeUrl  "/Sites/SubSite-xy"

    // if we fail to do the following
    // the user will be asked to choose a specific template from the standard interface

    // web.update() and close plus dispose to prevent further issues


    // now you may open web again as e.g. web2

In case you are still working with “web” you should know that on SQL level the site has been provisioned with ApplyWebTemplate but not the in-memory instance “web”. Check web.Provisioned and you will get False back. To fix possible problems upcoming later please close “web” and “reopen” it again. When using “web2” you can check that web2.Provisioned tells you True.



Blogs on MSDN: http://www.bing.com/search?cp=1252&FORM=FREESS&q=SPWebProvisioningProvider&q1=site:blogs.msdn.com

Blogs on TechNet: http://www.bing.com/search?cp=1252&FORM=FREESS&q=SPWebProvisioningProvider&q1=site:blogs.technet.com

Method ApplyWebTemplate http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.applywebtemplate.aspx

WebTemp.xml http://msdn.microsoft.com/en-us/library/ms447717.aspx

How to: Create a Custom Site Definition and Configuration http://msdn.microsoft.com/en-us/library/ms454677.aspx

Skip to main content