您的位置:首页 > 其它

How to: Create a Custom List Definition

2011-09-21 14:18 274 查看
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

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.

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>


To replace the GUID placeholder in the previousId attribute, generate a GUID by running guidgen.exe, located inLocal_Drive
:\Program Files\Microsoft Visual Studio 8\Common7\Tools
.

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>


Create a subfolder that has the same name as that assigned to the list template in the previous step, for example, SimpleList.

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.

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


To test the new Feature, navigate to theCreate 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 theItem 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 theContentTypes section ofSchema.xml, add a field definition for the
FavoriteColorChoice 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: