Thursday, October 23, 2008

Building a SharePoint custom site definition with a project tasks list and a listviewwebpart in Gantt view on the homepage.

The next walkthrough will show you how you can create custom site definition with specific lists and their associated listviewwebparts on the homepage - as an example I will use the new Project Tasks list type in SharePoint 2007.  To get you going first take a look at Creating a custom site definition in WSS V3/MOSS 2007. Start off with something simple such as a completely blank custom site definition.

Next let's add a new list instance of type Project Tasks to the site definition - to do this open up ONET.XML and navigate to the <Lists> node - for the Project Tasks you will need to add the line marked in bold.

<Configuration ID="0" Name="Default">
      <Lists>
      <List FeatureId="00BFEA71-7E6D-4186-9BA8-C047AC750105" Type="105" Title="Contacts" Url="Lists/Contacts" />     
         <List FeatureId="00bfea71-513d-4ca0-96c2-6a47775c0119" Type="150" Title="Project Tasks" Url="Lists/ProjectTasks" />
      </Lists>

Now, how did I find the FeatureId and the Type - well quite simply - just try creating a new Project Tasks list through the UI and you will notice this in the URL - http://[servername]/SiteDirectory/demo/_layouts/new.aspx?FeatureId={00bfea71-513d-4ca0-96c2-6a47775c0119}&ListTemplate=150

Looks similar no?

Next, let's add a web part on the home page which will display the items in the Project Tasks list - the webpart which does this is the listviewwebpart. Again, you have to modify ONET.XML - take a look at the line in bold.

<Module Name="Default" Url="" Path="">
      <File Url="default.aspx" NavBarHome="True">
        <NavBarPage Name="$Resources:core,nav_Home;" ID="1002" Position="Start" />
        <NavBarPage Name="$Resources:core,nav_Home;" ID="0" Position="Start" />
         <View List="Lists/Contacts" BaseViewID="0" WebPartZoneID="Left" WebPartOrder="1" />
<View List="Lists/ProjectTasks" BaseViewID="0" Type="GANTT" WebPartZoneID="Left" WebPartOrder="2" />
      </File>     
    </Module>

Again, how did I find out about the BaseViewID and the Type property. I first searched for the feature with ID=00bfea71-513d-4ca0-96c2-6a47775c0119 in the Features folder underneath the 12 hive - apparently the Project Tasks list is based on the GanttTasksList feature. If you want to know about the available views  which you can use in the listviewwebpart take a look at the schema.xml file.

Once you understand how you do this for the standard list definitions you can do something similar for custom list definitions as well. Happy sharepointing ...

1 comment:

Jeroen Van Bastelaere said...

Do you have a solution for disabling the toolbar (similar to changing the schema.xml like: < ToolBar Type="None" />) on a listviewwebpart when you add the new view through code?

Regards,

Jeroen