The CustomSchema attribute of the ListInstance feature element is a new attribute introduced in SharePoint 2010. What it does is pretty simple – it allows you to exchange the metadata of the list instance that you make (I was complaining about the lack of this capability in SharePoint 2007). The thought is pretty simple – in the CustomSchema attribute you specify the feature root relation path of a list machinate file which is really a normal list classification machinate.xml file and that is basically it – you have all metadata elements from the machinate in your new list instance. So, it doesn’t seem like a huge deal because you can achieve the same thing with a custom list classification and a list instance based on it – and yes this is obviously the preferred thing to do when you have many instances that should be based on the same list machinate. But on the other hand if you have many list instances all with different schemas (basically with some insignificant customizations – several new fields and some list views) you can go on with this kind of small-cut implementation which is far more economical. Another excellent thing to know here is that since the list machinate file is the same as in a list classification you can always promote it to a custom list template classification (with just adding a list classification element and moving the machinate to it) in case you need to make more than one list instance based on that machinate. The opposite thing is also possible – you can “demote” a list classification item with just keeping its machinate for the CustomSchema attribute of a ListInstance and removing the list classification element itself. Note here that the list machinate file that you use in the CustomSchema should contain all major elements of the List/MetaData section – ContentTypes, Fields, Views, Forms – it’s not like the ListInstance element uses its base list classification (specified in the FeatureId attribute) and applies the CustomSchema as modifications on top of it – really the list machinate specified in the CustomSchema attribute should be a fully-fledged list machinate and if you miss some of its elements you will receive various errors on feature activation or later when you are by the list. And since you have a fully-blown list machinate it is that undemanding to have the machinate reused to or from a custom list classification.

Another advantage of by a ListInstance with CustomSchema is that it can be tested very easily: you don’t need an iisreset (or recycle the app pool) after you make a exchange in the list machinate – you just need to delete the list instance and make it again. Really you can first make and test your list machinate this way and only after place it in a custom list classification.

Another thing that may be bothering is the size of the list machinate files – you remember the huge machinate.xml files containing tons of CAML in SharePoint 2007 – well, this is not the case any more – except several mandatory items you can now place mostly the customizations that you need and the machinate file is still pretty small – several kilobytes or so – I will show you a sort of minimalistic machinate.xml file not more than.

So here is a sample ListInstance element with a CustomSchema attribute:

  <ListInstance Title="ListInstance2"

                OnQuickLaunch="TRUE"

                TemplateType="100"

                FeatureId="00bfea71-de22-43b2-a848-c05709900100"

                Url="Lists/ListInstance2"

                CustomSchema="ListInstance2/Machinate.xml"

                Description="">

And the custom (minimalistic) list machinate file that I used for it:

<List xmlns:ows="Microsoft SharePoint" Title="Basic List" EnableContentTypes="TRUE" FolderCreation="FALSE" Direction="$Resources:Direction;" Url="Lists/Basic List" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/">

  <MetaData>

    <ContentTypes>

      <ContentTypeRef ID="0x0100678499b7e7024385820d8586270c1a75" />

    </ContentTypes>

    <Fields></Fields>

    <Views>

      <View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,objectiv_schema_mwsidcamlidC24;" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/generic.png" Url="AllItems.aspx">

        <XslLink Defaulting="TRUE">main.xsl</XslLink>

        <RowLimit Paged="TRUE">30</RowLimit>

        <Toolbar Type="Standard" />

        <ViewFields>

          <FieldRef Name="Attachments" />

          <FieldRef Name="LinkTitle" />

          <FieldRef Name="Comments" />

        </ViewFields>

        <Query>

          <OrderBy>

            <FieldRef Name="ID" />

          </OrderBy>

        </Query>

      </View>

    </Views>

    <Forms>

      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

    </Forms>

  </MetaData>

</List>

A small explanation about the list machinate above – so you see all major elements – ContentTypes, Fields, Views and Forms in the MetaData section – the Fields element even empty should be present (yes, otherwise you will receive an error on feature activation). In the ContentTypes element there is a single ContentTypeRef element which attaches a site make pleased type to the list, the Fields element should normally contain all fields that should exist in the list, including the ones that are in the attached make pleased types. A pretty nasty thing here of having to define a set of fields first as site columns and then in every list classification that uses the containing make pleased type, isn’t it. I will demonstrate a work-around for the field redefinition issue in one of the next postings. Basically instead of ContentTypeRef you can use a ContentType element and define an inline list make pleased type which uses site and/or list columns (both types alike provided in the Fields element).

In the Views element I’ve defined a single list view – pretty simple at that. You can see several FieldRef elements in the ViewFields of the view, the last one is really for a field from the referenced site make pleased type  – don’t agonize that the field is missing in the Fields element – this won’t break the activation of the feature and can be fixed afterwards. The last metadata element is the Forms one – it is austerely hackneyed from a standard list classification machinate and just defines the new, edit and show forms of the list.

The last bit in the sample machinate worth noting is the EnableContentTypes attribute in the machinate root element. It should be set to right even if you have just one make pleased type in the list, otherwise in the new item menu in the all items view page of the list you will see the defaulting “new item” categorize instead of the actual name of your make pleased type.

Check it out:Stefan Stanev’s SharePoint blog