1.Create a Feature MyCustomLists as per directory structure shown in the image.
2.Feature.xml:
<Feature Title="My Custom List Creation"
Id="A9767B45-DFA0-4077-B273-D43D35DA959E"
Description="This feature add the list template for custom list and one instance of the list"
Version="1.0.0.0"
Scope="Web"
Hidden="FALSE"
ImageUrl="MySharepointProject\AfricanPith32.gif"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ActivationDependencies>
</ActivationDependencies>
<ElementManifests>
<ElementManifest Location="MyCustomListTemplate.xml" />
<ElementManifest Location="MyCustomListTemplate\MyCustomListData.xml" />
<ElementFile Location="MyCustomListTemplate\schema.xml" />
</ElementManifests>
</Feature>
3.MyCustomListTemplate.xml:
<ListTemplate
Name="MyCustomListTemplate"
BaseType="0"
Type="10111" //Should be unique number and only one list template in the site can use this type
OnQuickLaunch="TRUE"
SecurityBits="11"
Sequence="10000"
Category="Custom Lists"
DisplayName="My Custom List Template"
Description="My Custom List with image field."
Image="/_layouts/images/itgen.gif">
</ListTemplate>
4.Schema.xml: //Copy the schema.xml of CustList Feature from 12\Template feature folder and modify the following sections only.
<List xmlns:ows="Microsoft SharePoint"
Title="My Custom List"
Url="Lists/MyCustomList"
FolderCreation="FALSE"
Direction="$Resources:Direction;"
BaseType="0"
Type="10111"
Id="A9767B45-DFA0-4077-B273-D43D35DA959E" //Feature ID
xmlns="http://schemas.microsoft.com/sharepoint/">
Metadata Section: Refer Content Type
<MetaData>
<ContentTypes>
<ContentType ID="0x01"> //using the Item content type of sharepoint
<FieldRefs> //refer the custom columns which will be defined in the later section
<FieldRef ID="{a8eb573e-9e11-481a-a8c9-1104a54b2fbd}" Name="Priority" />
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" Required="TRUE" />
<FieldRef ID="{D84FBE02-4859-46c3-9A75-9DFD7B848BBB}" Name="Description"/>
<FieldRef ID="{B99D5EFC-9B70-44d4-B0C0-E831ABE01916}" Name="ImageUrl"/>
</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>
<Folder TargetName="Item" />
</ContentType>
<ContentTypeRef ID="0x0120" />
</ContentTypes>
Custom Columns Section:
<Fields>
<Field
ID="{a8eb573e-9e11-481a-a8c9-1104a54b2fbd}"
Type="Choice"
Name="Priority"
DisplayName="Priority"
SourceID="http://schemas.microsoft.com/sharepoint/v3"
StaticName="Priority">
<CHOICES>
<CHOICE>High</CHOICE>
<CHOICE>Normal</CHOICE>
<CHOICE>Low</CHOICE>
</CHOICES>
<MAPPINGS>
<MAPPING Value="1">High</MAPPING>
<MAPPING Value="2">Normal</MAPPING>
<MAPPING Value="3">Low</MAPPING>
</MAPPINGS>
<Default>Normal</Default>
</Field>
<Field ID="{D84FBE02-4859-46c3-9A75-9DFD7B848BBB}" Type="Note" Name="Description" NumLines="5" DisplayName="Description" Required="TRUE" />
<Field ID="{B99D5EFC-9B70-44d4-B0C0-E831ABE01916}" Type="URL" Name="ImageUrl" DisplayName="Image Url" Format="Image" />
</Fields>
View Fields Section: //Refer the custom columns which needs to appear in view
<ViewFields>
<FieldRef Name="LinkTitleNoMenu">
</FieldRef>
<FieldRef Name="Description" />
<FieldRef Name="ImageUrl" />
<FieldRef Name="Priority" />
</ViewFields>
4. MyCustomListData.xml: //This is the List Instance File which contains list data
<ListInstance
Id="MyCustomList"
FeatureId="A9767B45-DFA0-4077-B273-D43D35DA959E"
Title="My Custom List Instance"
Description="This is my custom list created using feature"
TemplateType="10111"
Url="Lists/MCL"> //path where the new list will be created
<Data>
<Rows>
<Row>
<Field Name="ID">1</Field>
<Field Name="Title">First</Field>
<Field Name="Description">My first custom text</Field>
<Field Name="ImageUrl">/_layouts/images/HOME.GIF</Field>
<Field Name="Priority">High</Field>
</Row>
<Row>
<Field Name="ID">2</Field>
<Field Name="Title">Second</Field>
<Field Name="Description">My second custom text</Field>
<Field Name="ImageUrl">/_layouts/images/ERROR.GIF</Field>
<Field Name="Priority">Normal</Field>
</Row>
<Row>
<Field Name="ID">3</Field>
<Field Name="Title">Third</Field>
<Field Name="Description">My third custom text</Field>
<Field Name="ImageUrl">/_layouts/images/ANNOUNCE.GIF</Field>
<Field Name="Priority">Low</Field>
</Row>
</Rows>
</Data>
</ListInstance>
Activate the Feature in the Site Features.
This list will be created on successful activation.
Possible Errors you may encounter.
1.Type ID already present for another list
2.View Fields not updated in schema,hence no item is visible.
3.Template name not same as custom list folder name.
4.Schema id not set to feature id.
Get the full code here:
http://www.mediafire.com/file/a1pthcdhn3twi88/MyCustomLists.zip

No comments:
Post a Comment