Home > SharePoint Development > Custom List Forms and List Templates

Custom List Forms and List Templates

Creating a deployable list template when the list uses custom forms containing the Custom List Form web part is not quite as straightfoward as it seems. 

Here’s the scenario:

Requirement: create a custom list and provide customised New, Edit and Display forms; then package the list template for deployment to a client’s SharePoint farm.

Proposed Solution: use SharePoint Designer to create custom forms for the list and then save the list as a List Template using the SharePoint UI or use the SharePoint Solution Generator to create a list definition solution in Visual Studio.

Creating the custom forms in SharePoint Designer is at first glance straightforward; see Sahil Malik’s blog for details of how to create a custom New item form.  The Edit and Display forms can be built in a similar fashion.

Important Note: you should be aware that using the Custom List Form web part causes the attachment functionality on the form to be broken.  An unsupported workaround does exist though, see Marc Davis’s blog for details. 

So at this stage the original list has custom NewForm, EditForm and DispForm pages associated with it.  Now all that was required was to save the list definition in some kind of deployable format.

There were two options considered: use the Save list a template option within the List Settings page to produce a .stp file, or use the SharePoint Solution Generator that comes with the Visual Studio extensions for WSS to create a list definition solution in Visual Studio.

In general, the two options appeared similar in terms of the lists produced from the templates; both can be used to create a new list which contains the columns and views defined within the original list.

Save list as template

The main difference seems to be that the Save list as a template option also retains any of the out-of-the-box SharePoint workflows associated with the list; something that may be a decisive factor if you are using one of the these workflows.

Unfortunately creating customised forms using a copy of the original form rather than the original form itself doesn’t quite work when the template contains a workflow. 

The problem is that there exist ‘hidden’ links to the original versions of the forms; these only show up when being referenced by internal SharePoint processes such as workflows.  In the scenario outlined above, any out-of-the-box workflow associated with the list continued to use the uncustomised form. 

The way around these ‘hidden’ links is to edit the original forms directly.  Save often. 

SharePoint Solution Generator

Running the SharePoint Solution Generator produces a Visual Studio project containing an aspx file for each form and view associated with the list together with the XML files that define the list. 

The schema.xml file is used to store the definition of the list’s fields, views, content types and associated forms.  The entry for a form is defined thus:

<Form Type="NewForm" Url="NewForm.aspx" WebPartZoneID="Main" />

List Definitions are deployed as SharePoint features and therefore the forms are also defined within the List Definition project’s feature.xml file:

<ElementFile Location="<feature name>\NewForm.aspx" />  

In order to make use of customised forms, you need to ensure that the uncustomised form definitions within the schema.xml and feature.xml files are replaced with the customised versions.

Well, that’s at least how it should work.  Unfortunately it doesn’t.

When the Custom List Form is added to the form page, it is created as a DataFormWebPart.  This web part takes a parameter called ListID; the default value of which is the GUID of the associated list.  The problem is that the default value of the ListID is never updated, so all instances of the list created from the template will attempt to use the same GUID.

Compounding this problem is the behaviour of the SharePoint Solution Generator.  In building the List Definition, the Solution Generator stripped the CustomNewForm of any customisations so that it uses the uncustomised ListFormWebPart.

Therefore I can’t recommend that anyone use the SharePoint Solution Generator to produce a list definition when working with forms customised with the Custom List Form web part.

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: