Introduction
In this article we will explain how to create a SharePoint 2010 List Definition using Visual Studio 2010.
Open Visual Studio 2010 then select "File" -> "New" -> "Project...".
Select the Visual C# -> SharePoint 2010 --> List Definition project template.
Enter "MyTestList" in the Name TextBox and click on OK.
In the SharePoint Configuration Wizard select "Deploy as farm solution" and click on "Next".
In the Solution Explorer, expand ListInstance1 and open the Elements.XML file:
Within the ListInstance element change the Title attribute to MyTestList and change the TemplateType attribute to 10009.
Now, open the Elements.xml file that is on the same level as ListDefinition1.
Within the ListTemplate element, change the Type attribute to “10009” and add the DisallowContentTypes=”FALSE” attribute, as shown below:
In this article we will explain how to create a SharePoint 2010 List Definition using Visual Studio 2010.
Open Visual Studio 2010 then select "File" -> "New" -> "Project...".
Select the Visual C# -> SharePoint 2010 --> List Definition project template.
Enter "MyTestList" in the Name TextBox and click on OK.
In the SharePoint Configuration Wizard select "Deploy as farm solution" and click on "Next".
Enter "MyTestList" in the What is the display name of the list definition? TextBox.
Select "Custom List" in the What is the type of the list definition? Drop-down box. Within the ListInstance element change the Title attribute to MyTestList and change the TemplateType attribute to 10009.
- <?xml version="1.0" encoding="utf-8"?>
- <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
- <ListInstance Title="MyTestList"
- OnQuickLaunch="TRUE"
- TemplateType="10009"
- Url="Lists/MyTestList-ListInstance1"
- Description=" My Test List Instance">
- </ListInstance>
- </Elements>
Now, open the Elements.xml file that is on the same level as ListDefinition1.
Within the ListTemplate element, change the Type attribute to “10009” and add the DisallowContentTypes=”FALSE” attribute, as shown below:
- <?xml version="1.0" encoding="utf-8"?>
- <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
- <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->
- <ListTemplate
- Name="ListDefinition1"
- Type="10009"
- BaseType="0"
- DisallowContentTypes="FALSE"
- OnQuickLaunch="TRUE"
- SecurityBits="11"
- Sequence="410"
- DisplayName="MyTestList"
- Description="My Test List Definition"
- Image="/_layouts/images/itgen.png"/>
- </Elements>
- Insert the following XML into the top of the Elements element in the
Elements.xml file. This XML describes the MyTestList Item content type
the list will store.
- <ContentType
- ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94"
- Name="My Test List"
- Group="Custom Content Types"
- Description="My Test List content type."
- Version="0">
- <FieldRefs>
- <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />
- <FieldRef ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" />
- <FieldRef ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" />
- <FieldRef ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" />
- </FieldRefs>
- </ContentType>
- <Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title" Group="Custom Columns" />
- <Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />
- <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />
- <Field Type="Text" DisplayName="Course" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="Course" Name="Course" Group="Custom Columns" />
Add the EnableContentTypes=”TRUE” attribute to the List element inside of the Schema.xml file.
- <List xmlns:ows="Microsoft SharePoint" EnableContentTypes="TRUE" Title="MyTestList"
- FolderCreation="FALSE" Direction="$Resources:Direction;"
- Url="Lists/MyTestList-ListDefinition1" BaseType="0"
- xmlns="http://schemas.microsoft.com/sharepoint/">
- <ContentTypes>
- <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />
- <ContentTypeRef ID="0x01">
- <Folder TargetName="Item" />
- </ContentTypeRef>
- <ContentTypeRef ID="0x0120" />
- </ContentTypes>
<Fields>
<Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6"
RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title"Group="Custom Columns" />
<Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />
<Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />
<Field Type="Text" DisplayName="City" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="City" Name="Course" Group="Custom Columns" />
</Fields>Insert the following XML into the ViewFields element in the 2nd view, BaseViewID="1":
- <ViewFields>
- <FieldRef Name="Attachments"></FieldRef>
- <FieldRef Name="LinkTitle"></FieldRef>
- <FieldRef Name="Title"></FieldRef>
- <FieldRef Name="ID"></FieldRef>
- <FieldRef Name="Name"></FieldRef>
- <FieldRef Name="City"></FieldRef>
- </ViewFields>
After deploying a List Definition, check this list in web application:
Go to Site Action -> More Options
You can see that your MyTestList template is created in the Installed Items template:
No comments:
Post a Comment