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

  • Anybody know?
    Monday, May 12, 2008 9:46 AM
  • use a list defintion instead, feature staple the list definition and list instance feaures to the site definition that you are using.
    Monday, May 12, 2008 11:03 PM
  • Do you mean that modify the My Site site definition? I think it's not good

    Tuesday, May 13, 2008 1:24 AM
  • Any other solution?
    Tuesday, May 13, 2008 12:20 PM
  • hehe

    Modifing the site defintion wouldn't be a great idea....

    What I'm suggesting is feature stapling, the concept here is that you have a feature that causes a set of features to be become associated with a given site definition.

    Both of these links will give you more information about feature stapling.
    http://blogs.msdn.com/cjohnson/archive/2006/11/01/feature-stapling-in-wss-v3.aspx
    http://www.sharepointnutsandbolts.com/2007/05/feature-stapling.html
    Wednesday, May 14, 2008 12:00 AM
  • Yes, I have used the feature stapling. But how to create the custom list instance based on a list template file(aa.stp) while creating MySite?

    Wednesday, May 14, 2008 1:22 AM
  • As I said, don't use a list template, use a list definition feature and a list instance feature
    Wednesday, May 14, 2008 1:34 AM
  • Because my custom list will contain a custom webpart, if use a list definition, how to include the custom webpart?

    Wednesday, May 14, 2008 1:53 AM
  • Why does the list need a custom webpart?

    That seems very odd
    Wednesday, May 14, 2008 2:05 AM
  • By Default, while you creating a calendar list, it will show a calendar webpart which contains all month calendar items. Currenty, I create a custom calendar wepart to replace the original calendar webpart.

     

    I hope after user created MySite, it will automatically create a calendar list which will dispay my custom webpart instead of original calendar webpart.

    Wednesday, May 14, 2008 2:13 AM
  • Cool Smile

    Liek is said in my other post, VSeWSS will probably help.
    With VSeWSS you can ensure that the required web part is in the same package as the custom list definition. You can probably even crack open the .stp file and extract the code for the view that uses your custom web part Smile
    Wednesday, May 14, 2008 2:17 AM