Sarah is a Software Developer at SM Energy that our Catapult team in Denver has had the pleasure of working with recently. Her post below details how to create and link custom list forms with custom content types in SharePoint 2010. I know a lot of administrators and developers are frequently asked to find ways to streamline the content management process for site users and owners and this goes a long way in doing just that. If you have any questions about this solution, Sarah can be reached at [email protected] Thanks, Sarah, for sharing this great solution with us!
- Create custom content types with custom fields for multiple different task or document types.
- Create custom list definitions and list instances that will include multiple custom task types or multiple custom document types.
- Create custom display, edit and new item list forms associated with each custom content type so that when a user selects a list item, the associated custom form is displayed.
- In a SharePoint project in Visual Studio 2010, create each desired custom field and custom content type. Make certain to start the ID of the Content Type in the Elements.xml file with the desired parent content type such as Task or Document Type. This link is an excellent walkthrough on creating custom content types in Visual Studio 2010 http://msdn.microsoft.com/en-us/library/gg295290.aspx
In the Elements.xml file of the custom content type , below the FieldRefs element, edit the <XmlDocuments> element replacing the default <FormTemplates> element with a <FormUrls> element for each custom form that you are going to create as shown in this example.
Do not include a <Display>, <Edit>, or <New> element where you intend to use the default list form instead of a custom form. Replace MyTaskListName in the example with the name of the custom list instance that is associated with your custom content types in your SharePoint site. Create unique and meaningful names for each custom list form that you are going to create for this content type.
!!!You must include Lists/ at the beginning of each form url element if you are designing forms using SharePoint Designer 2010 as described in this article. If instead you are designing and deploying custom application pages in the Layouts/ folder, begin each form url element with Layouts/.
- Design and deploy a List Definition and List Instance in a SharePoint site that is associated with each desired custom content type. If creating the List directly in SharePoint, be sure to choose Advanced Settings and enable "Allow Management of Content Types". In the SharePoint list in List Settings, add each custom content type to be associated with items in this list. You can add multiple content types.
- In SharePoint Designer 2010, open the desired SharePoint site that contains your custom list that is associated with custom content types.
- Select Lists and Libraries from the Site Objects panel and select the desired custom list. You will see the List Information Summary page for your list similar to the one pictured below:
- In the Content Types pane at the lower left of this page, verify that you have added all of the custom content types that you want associated with this list.
- In the Forms pane in the middle of this page, you will see the default forms for this list:
- In the Forms pane, click the New button to create a new custom list form for this list. The Create New List Form dialog is displayed.
- In the File Name textbox, enter a unique name for this form such as DisplayNarrativeTask.aspx. Do not include a file path in the form name. Don’t overwrite the default list forms so that you can copy elements from or reuse those forms as needed.
- Select the type of form New Item, Edit Item or Display Item. Make sure that the type you select and the name of the form exactly match the FormUrls element of the custom content type you previously defined in your SharePoint project in Visual Studio and deployed to your SharePoint site. Don’t check the box "Set as default form for the selected type" unless you only have one content type associated with this list.
- In the advanced form options, select the custom content type you wish to associate with this form. You must have already deployed/created the custom content type and associated it with this list instance in order for it to appear in the drop down list. Click OK to close the dialog and create the form.
- The new custom form is now listed in the Forms pane of the List Information Summary page. Click on the name of the custom form in the list to open the form for editing. You can open multiple forms for editing at the same time. Each appears as a tab in the Designer interface. I won’t go into all of the details on how to edit a form in SharePoint Designer. By default the yellow highlighted areas are read-only and the white area of the form can be modified. For our site, we copied some display only fields from the Display form and replaced some fields in the Edit form so that some fields could not be edited in the Edit form but only edited in the New Item Form. We also removed some fields, reformatted fields and reordered fields.
- Be sure to save the changes you make to the forms. Create each form that you defined previously in the FormUrls element in the definition of each of your custom content types.
- Exit SharePoint Designer. Navigate to your custom list in your SharePoint site to test adding, editing and displaying items for each of your custom content types and associated custom forms. The custom forms will be associated with each item for an associated custom content type regardless of whether an item is added directly to the SharePoint list or is added from code or from a workflow.
- To copy or move this list and custom forms to another SharePoint site, you can Export the List and Import it into another SharePoint site. This will include associated custom content types and associated custom forms.
- To include the custom list instance forms and content type associations in a Visual Studio 2010 SharePoint project for packaged deployment, export the Site and import it into Visual Studio. You will see additional Pages and Schema files associated with the list instance that you created.