Partager via


SPWebProvisioningProvider and ApplyWebTemplate on publishing site definition (i.e.: BLANKINTERNET or custom)

While I am planning to soon blog on real life SPWebProvisioningProvider and Site Definitions in regards of Variations & Content Deployment, I wanted to comment on a little issue that had been plaguing me the last couple days.  First of all, my goal is to create a custom publishing site with :

  • More content types in the pages library
  • Update the default Parallel Approval workflow to have a different approvers group
  • Add a Delete Approval workflow
  • Have a custom default page that isn't a WelcomeLink

 

So that leads me to creating a custom Site Definitions.  Since the approval workflow parameters that I need are variable, I am working with the SPWebProvisioningProvider to update the workflow association after I created either a BLANKINTERNET#2 or a custom site definition that's similar to that one.  Note that BLANKINTERNET#2 is the standard Publishing Site with Workflow definition.  I found this blog (in French), https://blogs.developpeur.org/themit/archive/2007/10/18/sharepoint-deployment-feature-feature-solution-mais-aussi-webprovisioningprovider.aspx, that talks about how to do this and, unfortunately, it doesn't support comments so I'm commenting here.

 

Basically, you do a "web.ApplyWebTemplates("BLANKINTERNET#2");" followed by a "web.Update();".  Unfortunately, if you do an Update() right after applying a definition that activates the Server Publishing feature, it will give you an odd behaviour.  Basically, you end up having a "half publishing site" where you can edit the page, create a sub-site, but cannot create a new page or update navigation from the Site Actions.  I noticed that deactivating and reactivating the Server Publishing was working but the Navigation parameters were still off.

 

I then tried, by mistake :), commenting the "web.Update();" line and everything was working fine.  So beware if you use an Update() method call after doing an ApplyWebTemplate (you might require it depending on what you need to modify).  I didn't try that yet but you might be better off to do a "SPWeb updatedWeb = web.Site.OpenWeb(web.ServerRelativeUrl);" to get a new SPWeb variable.

 

Maxime

Comments