A field definition defines the columns that appear inside of the list template. For more information about the XML that is used to define a field type.
To create the field definition
- Start Microsoft Visual Studio 2010.
- On the File menu, point to New, and then click Project.
- In Project Types, under Visual Basic or C#, select Empty SharePoint Project.
- Type FavoriteColorList as the project name. Click OK.
- In the SharePoint Customization Wizard, choose Deploy as a sandboxed solution. Click Finish.
- In the Solution Explorer, right-click the FavoriteColorList project and select Add and then New Item.
- In the Add New Item dialog box, choose the Empty Element template and type FavoriteColorField as the Name. Click Add.
- Insert the following XML inside the Elements element. This XML defines a field for the content type.
You must replace FieldId in the ID attribute with a GUID. To generate a GUID, click Tools and then click Create GUID.
A content type defines a collection of items to use inside of the list. For more information about content types, see Content Types.
To create the content type
- In the Solution Explorer, right-click the FavoriteColorList project and select Add and then New Item.
- In the Add New Item dialog box, choose the Content Type template and type FavoriteColorContentType as the Name. Click Add.
- In the Choose Content Type Settings dialog box, choose Item in the Which base content type should this content type inherit from? drop-down list box. Click Finish.
- In the FieldRefs element, you must add a FieldRef element that references the field that you previously defined. The following XML adds a reference to the field.
The ID attribute of the FieldRef element must match the ID attribute of the Field element.
To create the list definition from the content type
- In the Solution Explorer, right-click the FavoriteColorList project and select Add and then New Item.
- In the Add New Item dialog box, choose the List Definition From Content Type template and type FavoriteColorListDefinition as the Name. Click Add.
- In the Choose List Definition Settings dialog box, ensure that FavoriteColorContentType is selected in the What content type would you like to use for your list definition? drop-down list box.
- Check the Add a list instance for this list definition option. Click Finish.
- Next, open the Schema.xml file that was created.
- In the ViewFields element, add the same FieldRef element that you added to the content type. The following XML adds a reference to the field.
The ID attribute of the FieldRef element must match the ID attribute of the Field element.
No comments:
Post a Comment