SPFieldCollection.Add method (String, SPFieldType, Boolean)

Creates a field in the collection based on the specified display name, field type, and Boolean value.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)


Public Function Add ( _
    strDisplayName As String, _
    type As SPFieldType, _
    bRequired As Boolean _
) As String
Dim instance As SPFieldCollection
Dim strDisplayName As String
Dim type As SPFieldType
Dim bRequired As Boolean
Dim returnValue As String

returnValue = instance.Add(strDisplayName, _
    type, bRequired)
public string Add(
    string strDisplayName,
    SPFieldType type,
    bool bRequired


  • strDisplayName
    Type: System.String

    A string that specifies the display name of the field.

  • bRequired
    Type: System.Boolean

    true if the field is required to contain a value; otherwise, false.

Return value

Type: System.String
A string that contains the internal name of the new field.


The Add method cannot be used to create a field of type Lookup, because this causes an SPException to be thrown. Instead use the AddLookup method to add a field of this type.


The following code example adds a required text field to the specified list.

Dim webSite As SPWeb = SPContext.Current.Site.AllWebs("MySite")
    Dim fields As SPFieldCollection = webSite.Lists("MyList").Fields

    fields.Add("MyField", Microsoft.SharePoint.SPFieldType.Text, True)
End Try
using (SPWeb oWebsite = SPContext.Current.Site.AllWebs["MySite"])
    SPFieldCollection collFields = oWebsite.Lists["MyList"].Fields;
    collFields.Add("MyField", Microsoft.SharePoint.SPFieldType.Text, 


Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

See also


SPFieldCollection class

SPFieldCollection members

Add overload

Microsoft.SharePoint namespace