I've run into an enormously frustrating problem. I want to add a Webpart to every page that's created on a certain site. I made an "Item was added to Pages library" Event Receiver, and am using the following code:

public class PageCreationEventReceiver : SPItemEventReceiver
    public override void ItemAdded(SPItemEventProperties properties)

    private void AddWikiPageWebPart(SPListItem item)
        SPFile file = item.File;
        SPLimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
        EditLabelsButton.EditLabelsButton wp = new EditLabelsButton.EditLabelsButton("Labels");
        wpm.AddWebPart(wp, "Side", 0);

The strangest thing is that when I enter Debug mode on my test environment, the code works fine. The webpart is added to every page I create. However, when I do a regular deploy to my test environment, I first need to reboot the whole machine. Then, I only see the webpart added on the first page I create. Any page created after that doesn't have the webpart.

Deploying to my live environment, it doesn't do anything. Even after a system reset, no webpart ever shows up. I'm at a loss as to what's causing this problem.

Does anyone here have an idea?

Thanks in advance!


I ended up programmatically attaching the EventReceiver to solve this problem. Inspiration taken from http://bramnuyts.be/2011/04/01/add-an-event-receiver-to-a-specific-list-programmatically/

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.