次の方法で共有


A ListDefinition with custom forms

Writing a custom ListDefinition is something all SharePoint developers phase more than once in a development lifecycle. With the new enhancements to the development tools for SharePoint 2010 it became actually easier to do so. But the tricky part is how to write a custom display, new and edit forms for the new list definition. Usually this task can be done easily by registering a new content type and associating this content type with a custom ASPX page that is deployed in the layouts folder. Usually this approach is not recommended and in some situations cannot be performed.

The solution is to develop custom ASPX pages that gets installed within the feature that installs the list definition and then deployed once a list is created from this definition. To do so it is rather simple.

First you need to have created the custom fields along with the custom content type to be added to the custom list. Also as a best practice it would be better to create custom controls to display and edit this new content type and add all these items to the feature definition. Now although these things are not mandatory but it would be best this is the best practice in this situation.

Then create a new list definition either from the already created content type above or as a new custom list as below.

image

This would contain the following files:

Index

File name

File description

1

Elements.xml

This contains the list definition name, description, … etc..

2

Schema.xml

This contains the exact definition of the list definition and the content types and views.

Now you need to add to the list definition folder the required custom forms as:

  1. DispForm.aspx
  2. EditForm.aspx
  3. NewForm.aspx

In these custom ASPX pages you would add references to the created ASCX custom controls already created to handle the display addition and editing of this new content type.

Now what remains is to add reference to these files in the feature to deploy the list definition and then to edit the Schema.xml to add reference to the new forms. This is done easily by editing the forms section as below:

image

You just need to replace the [Feature_Name] with the exact feature name which in VS2010 would be the in the following format:

<project name>_<Feature name>

Also the [Listdefinition_Folder_Name] is usually the name of the list definition.

I hope this helps you creating new list definitions easily.

Comments

  • Anonymous
    October 31, 2011
    why you used SetupPath and not path?