I assume you already have created custom Fields (Site Columns) and Content Types in VS2010.
The steps to take are:
- Create ListDefinition
- (optional) Create ListInstance
- Create a custom page that will hold the customizations
- Customize ListDefinition schema
- Deploy the solution, activate feature
In VS2010, you have a choice to create a new ListDefinition based on Content Type and just a plain ListDefinition. In this demo I chose the latter.
I want to create a List Definition based on Custom list. I also create to create a List Instance (Step 2) so after deployment I immediately have a custom list created.
Step 3: Create a customized NewForm
In schema.xml of the ListDefinition you see this line:
<Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
The SetupPath point to the 14-hive\templates folder. So In this case it will provision a NewForm.aspx based on the C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\Pages\form.aspx
You don't want to change this out-of-the-box page. It will void you support from Microsoft ;-).
So make a copy, copy it into the ListDefinition project and rename it to MyNewForm.aspx. Make sure you include MyNewForm.aspx into the VS2010 project and set the 'Deployment Type' to ElementFile, this will deployed the file to the feature directory. It should now look like this in VS2010.
Add some content to the NewForm:
Open the MyNewForm.aspx and look for the PlaceHolderMain ContentPlaceHolder (Line 244).
Put some content like <h1>Hello Customized World</h1> in front of the the <table …> a few line below.
Add a Web Part Zone to the NewForm:
Add: <WebPartPages:WebPartZone runat="server" FrameType="None" ID="Top" Title="loc:Top" /> after the <h1>Hello…
So it will look like this:
Save the changes ;-).
Step 4 Change the Schema.xml
Now we have created a custom page, however we need to tell the ListDefinition to use the customize NewForm. To do this, we need to change the Form element in the ListDefinition schema.xml
What I've done is:
- instead of using the default /pages/form.aspx, I told it to use the MyNewForm.aspx (So I changed SetupPath="pages/form.aspx" to Path="MyNewForm.aspx", it should not look into the template directory but in the feature directory, so SetupPath => Path…). The file will still be accessible with url NewForm.aspx. You can change that if you want.
- UseDefaultListFormWebPart="False", it will not add a default ListFormWebPart, but it will process the <WebParts> child elements.
- The <WebParts> child elements are used to place web part on the Custom MyNewForm.aspx
- first web part is a ListFormWebPart. When setting the PageType to PAGE_NEWFORM, it will add a ListFormWebPart that will handle the 'New Item' rendering, make sure the WebPartZoneID matches with the ZoneID's in the customized form. Default there's a Main ZoneID.
- second web part is a Image Web Part, showing a default MS SharePoint logo. This web part will be placed in the Top WebPartZoneID (our custom WebPartZone).
Deploy the solution using VS2010.
Visit the site where you deployed the solution. If VS2010 didn't automatically activated the feature, you should go to Site Settings, Manage Site Features and look for feature 'CustomListDemo Feature1' (This is why a naming convention is recommended ;-)). So make sure it's activated.
As the feature included a listinstance a list is created. The list name is: "CustomListDemo - ListInstance1".
Go to this list and click on 'New Item'.
This will be the result:
As you can see. The custom NewForm, including some custom content, a custom Web Part and the default ListFormWebPart. This is just a simple example. But you could go wild on the content and on adding your own Web Parts. It's also possible to change the template the ListFormWebPart uses. But that's for another day…
Read some more about Customizing Form.
You can follow me on twitter