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 am trying to ensure that a custom feature that I have written is activated when an SPWeb is created, and it has to be activated after all lists/libraries have been created (specifically the document library).

The feature's purpose is to hide the document libraries and deactivate the document library feature (dont ask). It throws an exception if its included in the WebFeatures tag in the onet.xml and from what I remember the feature stapling events fire before the lists are created.

Can anyone tell me what my options are regarding this?

Thanks.

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

You basically have to create a custom SPWebEventReceiver and activate your mandatory feature under "WebProvisioned" method, like this:

public class YourWebEventReceiver : SPWebEventReceiver
{
       public override void WebProvisioned(SPWebEventProperties properties)
       {
           base.WebProvisioned(properties);
           // Activate your mandatory feature here
           // site.Features.Add(featureId) #pseudo-code.
       }
}

If you need a step-by-step instruction to create a custom SPWebEventReceiver and deploy it, I found the following post helpful:

http://blog.qumsieh.ca/2010/10/07/how-to-attach-an-event-receiver-to-the-web-added-event-and-for-what-purpose/

share|improve this answer
add comment

SPWebProvisioned Event Handler

share|improve this answer
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.