none
How to create a list based on a custom list template in My Site?

    Question

  • I need to create a list based on a custom list templsate while creating My Site. The first step is that uploading the custom list template to List Template Gallery. I refer the post: http://www.sharepointblogs.com/tonstegeman/archive/2007/07/10/deploy-a-sharepoint-list-template-to-sharepoint-mysites.aspx. It can work. The second step is that creating a list instance according to the uploaded list template. I add following code in the featureActivated event:

    SPListTemplateCollection collection = site.GetCustomListTemplates(site.RootWeb);

    SPListTemplate type = collection["My Calendar"];
    site.RootWeb.Lists.Add("My Calendar", "This is my calenar", type);

    The My Calendar is my cusotm list template name.When I creating My Site, it will create failed. The error is that GetCustomListTemplates method can't find the custom list template while creating My Site.

    Then I modied my code as below:
    if(
    collection.length > 0)
    {
        
    SPListTemplate type = collection["My Calendar"];
         site.RootWeb.Lists.Add("My Calendar", "This is my calenar", type);
    }

    My Site can be created successfully. Then I deactivatte the feature and active the feature again. The custom list can be added to My Site and
    GetCustomListTemplates method can find the custom list template.

    The problem is that while you creating your My Site, the custom list template can be not found with
    GetCustomListTemplates method, if you created the My Site first and active the feature,the custom list template can be found with GetCustomListTemplates method. So how to get the custom list template while creating My Site?


    Sunday, May 11, 2008 8:17 PM

All replies