SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have created a custom web template based on Team Site and added a SPWeb scoped feature to add a List View WebPart to it. It throws an exception when it comes to web.Lists["Documents"] and says documents not exists. But when the web is created it has a documents list. I tried to add a call back as follows to be sure that the web is provisioned. The site is created however it still does not contains a listviewWebpart.

 public override void FeatureActivated(SPFeatureReceiverProperties properties)
     var web = properties.Feature.Parent as SPWeb;
     ThreadPool.QueueUserWorkItem(new WaitCallback(AddWebParts), web.Site.ID);

  private void AddWebParts(object state)
        Guid siteId = (Guid)state;
        SPWeb web = null;

        while (true)
            using (SPSite site = new SPSite(siteId))
                using (web = site.OpenWeb())
                    if (true == web.Provisioned)
  and so on to add listview webpart
share|improve this question
in your site, goto siteactions and check to see the full lists of document librarys and list! check to make sure Documents exists and that its called Documents ;) also make sure that the feature that your activating is the same spweb that contains the list/document library – ali Sharepoint May 28 '13 at 14:28
thanks ali but it is not the case, I solved it by using a Web event receiver so that it adds the listview webpart when the web provisioned. – user12955 May 28 '13 at 14:35

You should make sure that the features creating the Document Library and the page are prior to your feature in the Onet.xml. See Site Definitions vs. Web Templates for the order things are provisioned in.

share|improve this answer
Thanks, as I wrote in my question, I have copied directly the onet.xml so it should have same features that oob site definiton has. Do I need to add some oob features? which one? – user12955 May 28 '13 at 13:11

Your Answer


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.