Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Add method of the SPFieldCollection class creates a field in the collection.
Parameters
strDisplayName A string that specifies the display name of the field.
type A Microsoft.SharePoint.SPFieldType value that specifies the type of field to create.
bRequired true to require that the field contain a value; otherwise, false.
Return Value
A string that contains the display name of the new field.
Remarks
The Add method cannot be used to create a field of type Lookup, which causes an SPException exception to be thrown. Instead use the AddLookup method to add a field of this type.
Example
The following code example adds a required text field to the specified list.
This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.
Requirements
Platforms: Microsoft Windows Server 2003
Security: Code Access Security