How to: Create a Custom List Definition

This task demonstrates how to create a custom list template feature and add it to the selection of lists available for creating on theCreate Page. Adding a custom list feature requires that you provide at least the following three files:

  • Feature.xml registers the list template.

  • Elements.xml adds the list template to the Create Page.

  • Schema.xml defines the list schema, which includes content type associations, field and view definitions, and form and toolbar references.

Procedures

To add a custom list definition to a Web site

  1. Create a folder in Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATES\FEATURES and give it an appropriate name, such as SimpleListFeature.

  2. In the new folder create a Feature.xml file that specifies the title, ID, and scope for the Feature, as well as the location of an Elements.xml file, such as follows:

    <Feature 
      Title="Simple List Feature" 
      Id="80E23615-3145-4f43-BD5E-8524C02BD6CD" 
      Scope="Web" 
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
        <ElementManifest Location="Elements.xml" />
      </ElementManifests>
    </Feature>
    

  3. To replace the GUID placeholder in the previous Id attribute, generate a GUID by running guidgen.exe, located in Local_Drive :\Program Files\Microsoft Visual Studio 8\Common7\Tools.
  4. In the new folder create an Elements.xml file that identifies the list template and specifies information to display on theCreate Page. Give it a Type value that is above 10000 and different from any other custom list definitions used in your deployment:

    <Elements 
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ListTemplate 
        Name="SimpleList" 
        DisplayName="Simple List" 
        Type="10001" 
        Description="This is my simple list." 
        BaseType="0" 
        OnQuickLaunch="FALSE" 
        SecurityBits="11" />
    </Elements>
    

  5. Create a subfolder that has the same name as that assigned to the list template in the previous step, for example, SimpleList.
  6. Create a Schema.xml file in the new subfolder to define the list. You can copy and modify the Schema.xml file of an existing list Feature to define special fields for a custom list definition.

  7. At a command prompt, type the following commands to install the Feature in the deployment, and then activate the Feature on a specified subsite.

     
       a. stsadm -o installfeature -filename SimpleListFeature\Feature.xml
       b. stsadm -o activatefeature -name SimpleListFeature -url http://Server/Site/Subsite
    

  8. To test the new Feature, navigate to the Create Page and create a list through the template.

Schema.xml File

Define any custom fields that are required for your list near the beginning of theSchema.xml file. The following example, which copies and modifies the Schema.xml file of the defaultCustomList Feature, defines a special Choice field for the SimpleList Feature and adds this field to theItem content type so that the field is displayed in item forms.

To customize the Item content type definition, find the following content type declaration near the beginning of your copied Schema.xml file:

<ContentTypeRef ID="0x01">
  <Folder TargetName="Item" />
</ContentTypeRef>

Replace this content type declaration with the Item content type definition whose ID equals 0X01 in the ctypeswss.xml file that is located at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ctypes.

Add a reference for your custom field to the content type definition, which in this example is called FavoriteColor. Also include the defaultFolder element to specify the resource folder for the content type. Create a unique ID for your content type as described inContent Type IDs. Use guidgen.exe as describe previously in step 3 to create GUIDs for the content type ID and for the field reference.

<List Name="SimpleList" Title="Simple List" BaseType="0" Direction="" Url="">
  <MetaData>
    <ContentTypes>

  <!--Copy the referenced ContentType definition from ctypeswss.xml.-->
      <ContentType 
        ID="0x010099FE4F3ACD494e30A36693F9EE65BAF2"
        Name="FavoriteColor Item"
        Group="$Resources:List_Content_Types"
        Description="Favorite color item content type."
        Version="0">
        <FieldRefs>
          <FieldRef 
            ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" 
            Name="Title" 
            Required="TRUE" 
            ShowInNewForm="TRUE" 
            ShowInEditForm="TRUE"/> 

          <!--Add a field reference for the custom field.-->
          <FieldRef
            ID="{AD22016D-BC8B-4631-A0A3-5E84C6CFA7EC}" 
            Name="FavoriteColor" 
            Required="TRUE" 
            ShowInNewForm="TRUE" 
            ShowInEditForm="TRUE"/>

        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
              <Display>ListForm</Display>
              <Edit>ListForm</Edit>
              <New>ListForm</New>
            </FormTemplates>
          </XmlDocument>
        </XmlDocuments>

        <!--Include the relative folder path for the content type resource folder.-->
        <Folder 
          TargetName="Item" />
      </ContentType>

      <ContentTypeRef 
        ID="0x0120" />
    </ContentTypes>

In the empty Fields tag that follows the ContentTypes section of Schema.xml, add a field definition for the FavoriteColor Choice field, as follows:
    <Fields>
      <Field 
        Type="Choice" 
        Name="FavoriteColor" 
        DisplayName="Favorite Color">
        <CHOICES>
          <CHOICE>Red</CHOICE>
          <CHOICE>Green</CHOICE>
          <CHOICE>Blue</CHOICE>
        </CHOICES>
      </Field>
    </Fields>
    <Views>
      ...

Add a reference to the custom field in the ViewFields section of a view definition so that the field is displayed in the view. The following example adds a FavoriteColor field reference to the standard all items view.
<ViewFields>
  <FieldRef Name="Attachments"/>
  <FieldRef Name="LinkTitle"/>
  <FieldRef Name="FavoriteColor"/>
</ViewFields>

 

 http://msdn.microsoft.com/en-us/library/ms466023(v=office.12).aspx

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值