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 created a custom web template based on Team Site and added a spweb scoped feature to add a list view web part 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)
                    {
                        break;
                    }
                }
            }
            Thread.Sleep(100);
        }
   ....
  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
1  
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

1 Answer 1

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

 
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.