Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a code from external developer that creates site in list event receiver.

 public override void ItemAdded(SPItemEventProperties properties)
        {
            bool EventFiringEnabledStatus = EventFiringEnabled;
            ReceiverParams param = new ReceiverParams(properties);
            EventFiringEnabled = false;
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite site = new SPSite(properties.SiteId))
                    {
                        using (SPWeb web = site.OpenWeb(properties.Web.ID))
                        {
                            if (!IsWebExists(web, name))
                            {
                                bool allowUnsafeUpdates = web.AllowUnsafeUpdates;
                                try
                                {
                                    web.AllowUnsafeUpdates = true;
                                    SPWebCollection collection = web.Webs;
                                    SPWeb projectWeb = collection.Add(name, title, description, culture_LCID, templateName, true, false);
                                    projectWeb.Update();
                                    isCreated = true;
                                }
                                finally
                                {
                                    web.AllowUnsafeUpdates = allowUnsafeUpdates;
                                }
                            }
                        }
                    }
                });
            }
            finally
            {
                EventFiringEnabled = EventFiringEnabledStatus;
            }
        }

I want to customize the site using WebProvisioned event receiver:

 public override void WebProvisioned(SPWebEventProperties properties)
        {
            System.Diagnostics.Debugger.Break();
            base.WebProvisioned(properties);
        }

This event fires when i create site from web interface or from my own code. But it does not fires when the site is created in list event receiver. There is only "Error loading and running event receiver : Thread was being aborted." in logs.

share|improve this question
    
Please provide the details of list event receiver you use to create site. –  Amit Kumawat Apr 9 '12 at 13:46
    
I have added the code that creates site with system user's permissions. –  Ruslan Dayanov Apr 9 '12 at 14:16
1  
Are you creating a subsite or a nwe root site in a site collection? –  Anders Rask Sep 1 '12 at 9:08
add comment

2 Answers

This row

EventFiringEnabled = false;

is telling the code to not fire the WebProvisioned event, so that is why your event receiver does not trigger.

share|improve this answer
add comment

You may want to check if the Event Receiver is registered (using SharePoint Manager) and verify if it needs to be scoped at Site level rather than at Web level (the Webprovisioned event does not get fired for the root web). Here's a good post giving details on WebProvisioned event receiver – a practical example.

UPDATE: The differences in the two scenarios may lie in the context (HTTPContext v. SPContext) - this can be verified by posting events in the ULS logs.

share|improve this answer
1  
Thank you for answer. It has a site level scope. It really works when i am creating site. The actual question is what can prevent it from firing when site is created from list item event receiver? Can it be EventFiringEnabled=false in parent event receiver? –  Ruslan Dayanov Apr 9 '12 at 13:52
    
I have updated my response above regarding the context (of your two scenarios). –  Supriyo SB Chatterjee Apr 9 '12 at 14:00
2  
Ruslan, you are on the right track with your comment. EventFiringEnabled=false quiets down the event model and is preventing WebProvisioned event from being raised during the list item event receiver. –  bkwdesign Jul 3 '12 at 14:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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