4

I am creating a SharePoint site from code behind using SharePoint object model. In the WebProvisioned event, I am creating the groups, enabling a few features. Everything is working fine, except the WebProvisioned event is firing twice. This only happening if I try to create the site using Object model, if a site is created using "New Site" option from UI, it is only firing once. I found a few article mentioning that when a site is created using object model the WebProvisioned event will be called twice, not sure why though.

Also, if I change the scope of the event receiver to "Web", WebProvisioned is called only once. But, I need this scoped at "Site" level.

Can you please tell me a work around at least?

Below are the articles I found,

http://stefan-stanev-sharepoint-blog.blogspot.com/2010/09/webprovisioned-event-receiver-practical.html

http://thesoftwarecondition.com/blog/2013/06/08/sharepoint-pain-points/

The second article says we can set the properties.cancel=true, so that it will cancel the event. But, I need to do it only when the event is being fired for the second time. Is there any way to do that? I couldn't find a way to do that.

  • It looks like you implemented a workaround. I stumbled across something that may help, but I haven't the time to experiment. Take a look at stefan-stanev-sharepoint-blog.blogspot.com/2010/09/…, particularly where he adds the line <Receivers Scope="Site">. He said it solved symptoms similar to those you describe. – kbrimington Dec 6 '13 at 19:28
1

For Now, I have used SPWeb.Properties to cancel the event when it is firing for the second time. I have added a custom property and set it to "true" when the web is provisioned first time. And, verified the custom property value at the start of WebProvisioned method, cancelled the event in case if the property value is true.

However, I would like to use a better approach than this temporary fix. Please let me know if you happened to have same issue and solved it in a better way.

Thank you..!!

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.