I have created a web template using the onet.xml and elements.xml. I have created a web provisioned event receiver, but it is not really attached to my custom web template. When I create a site the web event receiver will fire on every template, like: Team, Blank, etc. How can I attach it to fire only on my custom web template?


In your event receiver code you can check SPWeb.WebTemplate and decide whether the new web is being created using your custom template. If it is then you can apply your modifications to the web. For example:

void WebProvisioned(SPWebEventProperties properties)
    if(properties.Web.WebTemplate =="Your template"){
     //do stuff
  • I am going to give it a try. I will get back to you soon. Oct 29 '15 at 17:14
  • I tried it, but the properties.Web.WebTemplate returns the base template which is STS and not my custom template which is {guid}#templatename. How can I distinguish between my custom template and the other templates, like team site which has the same base template? Oct 29 '15 at 18:10
  • read this article if you are still stuck - search for the word "bag" on the page and start reading from there.blogs.msdn.com/b/vesku/archive/2010/10/14/…
    – HarryB
    Oct 30 '15 at 10:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.