Adding OTB list and our own custom list to the site.In the
first part i talked about creating a site definition from an existing site. This post talks about adding a links(MyLinks) list and a custom list (CustomListX) to the site definition.
Some background: When you want to create your own list definition, you can implement it as a sharepoint feature. When you implement as feature it is available to the whole sharepoint server, not to your specific site. It will not hurt anything, but it will mess the list of feature available to a site. For example the
Posts custom list in the
Blog template is available only when you create a blog site. The Posts list will not be available to any other site template, which makes more sense.
When we create our own site definition, we also want different list which should only available to our site, not for teamsite or blog site.
Now the implementation:
- Creating the whole list and its view mostly painful job. So create the list, in our example CustomListX, in any existing site, by selecting the Custom List type, add whatever column you want.
- Generate the list definition for the above list using Sharepoint Solution Generator app.
- Copy the CustomListX folder, which contains a schema.xml and other .aspx files, and keep it in the List folder, under your custom site definition folder.
- Now your folder structure looks like in the following image.
- Now open the schema.xml in the CustomListX folder and modify the List element as follows
1: <List Name="CustomListX" Title="CustomListX" Description="" Url="$Resources:core,lists_Folder;/CustomListX" Direction="0" BaseType="0" xmlns="http://schemas.microsoft.com/sharepoint/" >
- In the list element the url attribute tells, where the customlistx is located, and the basetype says it is a fresh template.
- Open the onet.xml and look for the ListTemplates element. The generated code does not caontain any tempaltes.
- Add the following element to ListTemplates element.
1: <ListTemplate Name="CustomListX" EnableModeration="False" DisplayName="CustomListX" Type="20001" BaseType="0" OnQuickLaunch="TRUE" FolderCreation="FALSE" AllowDeletion="FALSE" Unique="TRUE" DisallowContentTypes="TRUE" SecurityBits="11" Description="A sample custom List" Image="/_layouts/images/itposts.gif" />
- The Name attribute refers to the customlistx we kept in the site definition. The Type attributes identifies it with an id. so give a valid id anything from 10000. This attribute is 103 for links, 101 for document library, and etc. For all the Type id and the list type the msdn document is here. The Unique attribute says only only list can be created based on this definition. For example in the blog site we have only one posts list, and we no need to create again and again like link or tracking list.
- Optional. Now we will be creating the actual list to the site. Add the following List element to the Lists element in configuration element.
1: <List Url="$Resources:core,lists_Folder;/CustList1" QuickLaunchUrl="$Resources:core,lists_Folder;/CustList1/AllItems.aspx" Title="CustList1" Type="20001" />
- The Url attributes says the url for the newly crated list. We are crating a list, based on CstomListX, called CustList1. The Type attribute says, the list definition (template), in our case 20001 refers the CustomListX.
- Generate the wsp using th wspbuilder.
- Create a site based on our customSite definition, now our new site created with a list based on the CustomListX template
- The OTB list can be added to the site as the following List element in the Lists element.
1: <List FeatureId="00BFEA71-2062-426C-90BF-714C59600103" QuickLaunchUrl="$Resources:core,lists_Folder;/MyLinks/AllItems.aspx" Url="$Resources:core,lists_Folder;/MyLinks" Title="MyLinks" Type="103" />
- The FeatureId elements says the feature of the list. In the above example we are creating list, MyLinks, based on link list. The Type element says what list type it is.
I hope we can create our won site definition for any site template, like team site, based on this example.
[update]Download the sample code from
here.
Cheers,
Murugan G.
References:
- <12hive>\TEMPLATE\SiteTemplates\Blog