Compartilhar via


SPFieldCollection Class

The SPFieldCollection class represents a collection of SPField objects.

System.Object

   Microsoft.SharePoint.SPBaseCollection

      Microsoft.SharePoint.SPFieldCollection

Public Methods

The following table shows the public methods of the SPFieldCollection class and a brief description of each.

Name Description
Add Creates a field in the collection.
AddFieldAsXml Creates a field based on the specified XML definition.
AddLookup Creates a lookup field in the collection.
Delete Deletes the field with the specified internal name from the collection.
GetField Returns the field with the specified display name from the collection.
GetFieldByInternalName Returns the field with the specified internal name from the collection.

Public Properties

The following table shows the public properties of the SPFieldCollection class, the data type of each property, and a brief description of each.

Name Data Type Description
Count Int32 Gets the number of fields in the collection.
Item(Int32) Microsoft.SharePoint.SPField Gets the field object at the specified index in the collection.
Item(String) Microsoft.SharePoint.SPField Gets the field with the specified display name from the collection.
List Microsoft.SharePoint.SPList Gets the parent list of the collection.
SchemaXml String Gets the schema that defines the collection.

Thread Safety

Any public static (Shared in Microsoft Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

Use the Fields property of either the SPList or SPListItem class to return the collection of fields for a list or list item. To create a field, use one of the Add methods represented in the table above.

Use an indexer to return a single field from the collection. For example, assuming the collection has been assigned to a variable named myFields, use myFields[index] in C#, or myFields(index) in Visual Basic .NET, where index is either the index number of the field in the collection or the display name of the field.

For information about the fields used by default in a native SharePoint list, see Field Tables for Default Lists.

Example

The following code example iterates through all the lists in all the subsites under a site and, if it finds a list with a specified name, adds a new text field that is displayed in the default view of the list.

This example requires using directives (Imports in Visual Basic) for both the Microsoft.SharePoint and Microsoft.SharePoint.WebControls namespaces.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security