There is always a need for adding Custom List Pages (AllItems.aspx, DispForm.aspx, EditForm.Aspx & NewForm.aspx) to your list definition. By adding custom list pages to your custom List Definition
- You get more control on Customization of View, Edit and New form for your custom list definition
This is very easy to achieve. All you need to do is make your Custom List Definition refer those pages instead of default Out of Box pages. Below are steps
1. Making a Copy of existing files
Here instead of creating our own pages, you can just copy the existing pages.
- You can deploy your Custom List Definition to your development server.
- Create a List instance from your Custom List Definition
- Open Site in SharePoint Designer 2010
- Copy content of all list pages Allitems.aspx, DispForm.aspx, EditForm.aspx & NewForm.aspx to different files and named them MyAllItems.aspx, MyDispForm.aspx, MyEditForm.aspx & MyNewForm.aspx
- Now Open the MyAllItems.aspx and remove the code <WebPartPages:XsltListViewWebPart … > &
</WebPartPages:XsltListViewWebPart>. What you need to do just remove the XSLTLISTVIEWWEBPART from the MyAllItems.Aspx
- Save the modified file.
Follow above steps 1 to 4 or all other files. Please skip steps 5 & 6 for other files.
2. Deploying above files to Feature Folder
Here we will have to add all modified files to our solution in VS, so that those modified will be deployed to server when List Definitions features is deployed
- In Visual Studio add all above modified files to List Definition folder where you Schema.xml exists
- Open SharePointProjectItem.spdata file from your List Definition folder in VS
- Add below code
<ProjectItemFile Source=”MyAllItems.aspx” Target=”MyListDefinition\” Type=”ElementFile” /> in files tag.
similarly follow steps 2.1 to 2.3 for all other files
3. Changing the association of list pages
Now the final step is to associate modified list pages with List Definition.
- Open Schema.xml file of List Definition.
- Under <Forms>, remove attribute SetupPath=”pages\form.aspx” from all forms types like DisplayForm, EditForm & NewForm.
Note: By deleting the “SetupPath” attribute, we are telling SharePoint to look for “.aspx” pages named after the “Type” attribute in the same folder as Schema.xml
3. “AllItems.aspx” is associated with the default view of the list. so, delete “SetupPath” attribute from the default view node in the schema.
This is all we have to do for having custom list pages for list definitions.