locked
Provision a List Instance package without using List Template or Site Template RRS feed

  • Question

  • Hello,

    I've got a Feature package that I need to include creating a new Content Type and a (static) List Instance.  I need the List Instance to be provisioned fully functional, with Manage Content Types turned on and the correct Content Type assigned to it.  However, from what I've been reading, this is only doable with either a List Template def. or an onet.xml file and a site template.  Is there a way to just provision a List Instance (with the elements.xml file) without having to create either a List or Site template?

    Thanks.

    Wednesday, July 13, 2011 5:53 PM

Answers

  • Do not use the onet.xml and site template method. If you ask me your best bet is to use Visual Studio 2010 to create a new content type, then use VS to create a new list definition from content type, selecting your new content type. You can package these up in the same feature, along with a list instance for your new list definition, and all you need to do is activate the feature!

    However you seem to want to deploy a content type and a list instance, nothing else. Unfortunately you cannot provision a list instance without an underlying list definition - it would be like instantiating an object without the class existing, simply impossible, as a list instance has to be an instance of a list definition. However, you can provision an instance of a custom list (list template ID 100), then add a feature receiver to the feature provisioning the list instance. In the feature receiver you'd need a FeatureActivated which you could use to find the list programmatically then use the object model to add the content type to the list.

    Does that answer your question?

    • Proposed as answer by samdv1982 Thursday, July 14, 2011 5:21 AM
    • Marked as answer by sdfsda Friday, July 15, 2011 7:02 PM
    Thursday, July 14, 2011 5:12 AM
  • I agree. You can also then set the SPListContentTypesEnabled property (see http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.contenttypesenabled.aspx) equal to true to turn on 'Manage Content Types'.

    The other option if you don't wish to do it programmatically would be to use the CustomSchema attribute (new in SharePoint 2010) of the ListInstance element to specify a list schema in which you reference the custom content type and set EnableContentTypes = TRUE. This option does mean you have to define a list schema as you would if creating a list template/definition which you might be trying to avoid. However you could do this reasonably easily by using the UI to create the list as you want it and then examine the schema using the tools in Visual Explorer or other tool, such as SharePoint Manager 2010 (available on Codeplex). It does mean you are not having to create a full blown list template though.

     

    • Marked as answer by sdfsda Friday, July 15, 2011 7:02 PM
    Thursday, July 14, 2011 7:15 AM

All replies

  • Do not use the onet.xml and site template method. If you ask me your best bet is to use Visual Studio 2010 to create a new content type, then use VS to create a new list definition from content type, selecting your new content type. You can package these up in the same feature, along with a list instance for your new list definition, and all you need to do is activate the feature!

    However you seem to want to deploy a content type and a list instance, nothing else. Unfortunately you cannot provision a list instance without an underlying list definition - it would be like instantiating an object without the class existing, simply impossible, as a list instance has to be an instance of a list definition. However, you can provision an instance of a custom list (list template ID 100), then add a feature receiver to the feature provisioning the list instance. In the feature receiver you'd need a FeatureActivated which you could use to find the list programmatically then use the object model to add the content type to the list.

    Does that answer your question?

    • Proposed as answer by samdv1982 Thursday, July 14, 2011 5:21 AM
    • Marked as answer by sdfsda Friday, July 15, 2011 7:02 PM
    Thursday, July 14, 2011 5:12 AM
  • I agree. You can also then set the SPListContentTypesEnabled property (see http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splist.contenttypesenabled.aspx) equal to true to turn on 'Manage Content Types'.

    The other option if you don't wish to do it programmatically would be to use the CustomSchema attribute (new in SharePoint 2010) of the ListInstance element to specify a list schema in which you reference the custom content type and set EnableContentTypes = TRUE. This option does mean you have to define a list schema as you would if creating a list template/definition which you might be trying to avoid. However you could do this reasonably easily by using the UI to create the list as you want it and then examine the schema using the tools in Visual Explorer or other tool, such as SharePoint Manager 2010 (available on Codeplex). It does mean you are not having to create a full blown list template though.

     

    • Marked as answer by sdfsda Friday, July 15, 2011 7:02 PM
    Thursday, July 14, 2011 7:15 AM