views:

156

answers:

2

In MOSS 2007, is there a way I can insert a piece of code I wrote to run every time I create a site from a ready made template ??

+3  A: 

You should do it with a feature, and give it a feature receiver that contains your code. Attach the feature to the site template. If you've made the template yourself, you can simply add it to its onet.xml. If it's a standard template, you can use feature stapling, which connects your new feature to an existing site template.

Note that in either case, your code will not run for sites that exist already, (unless you manually activate the feature there.)

Bjørn Stærk
+3  A: 

Yes, you certainly can. I wrote a post on this a few months back. You have two options, either a feature with a feature activated handler, or using a ProvisionAssembly in your site defintions webtemp*.xml file. The latter is also how MOSS does the Publishing portal multi-site setup.

I wrote a short article on this a few months back: http://furuknap.blogspot.com/2008/06/question-from-forum-post-at-httpwww.html

.b

Bjørn Furuknap