SPField Class
The SPField class represents a field in a list on a SharePoint Web site.
System.Object
Microsoft.SharePoint.SPField
Public Methods
The following table shows the public methods of the SPField class and a brief description of each.
Name | Description |
---|---|
ToString | Returns the title of the field. |
Update | Updates the database with changes made to the field. |
Public Properties
The following table shows the public properties of the SPField class, the data type of each property, and a brief description of each.
Name | Data Type | Description |
---|---|---|
AuthoringInfo | String | Gets the descriptive string used in pages for editing fields to identify the field and its purpose. |
CanToggleHidden | Boolean | Gets a Boolean value that indicates whether the column can be hidden through the user interface. |
DefaultFormula | String | Gets or sets the default formula for a calculated field. |
DefaultValue | String | Gets or sets the default value for the field. |
Description | String | Gets or sets the description for the field. |
Direction | String | Gets or sets the direction of the reading order for the field. |
DisplaySize | String | Gets or sets the display size for the field. |
FieldReferences | String[] | Gets a string array that contains the names of fields referenced in a computed field. |
Filterable | Boolean | Gets a Boolean value that indicates whether the field can be filtered. |
FilterableNoRecurrence | Boolean | Gets a Boolean value that indicates whether a view filter for a view that does not expand recurring events can be created on a field that does not allow filtering. |
FromBaseType | Boolean | Gets a Boolean value that indicates whether the field derives from a base field type. |
Hidden | Boolean | Gets or sets a Boolean value that specifies whether the field is displayed in the list. |
IMEMode | String | Gets or sets the Input Method Editor (IME) mode bias to use for the field. |
InternalName | String | Gets the internal name used for the field. |
ParentList | Microsoft.SharePoint.SPList | Gets the parent list that contains the field. |
ReadOnlyField | Boolean | Gets or sets a Boolean value that specifies whether values in the field can be modified. |
Reorderable | Boolean | Gets a Boolean value that indicates whether values in the field can be reordered. |
Required | Boolean | Gets or sets a Boolean value that determines whether the field requires values. |
SchemaXml | String | Gets or sets the schema that defines the field. |
Sealed | Boolean | Gets a Boolean value that indicates whether other fields can be derived from the field. |
Sortable | Boolean | Gets a Boolean value that determines whether the field can be sorted. |
Title | String | Gets or sets the display name for the field. |
Type | Microsoft.SharePoint.SPFieldType | Gets or sets the type of the field. |
TypeAsString | String | Gets the type of the field as a string value. |
Thread Safety
Any public static (Shared in 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 class or the SPListItem class to return an SPFieldCollection object that represents the collection of fields for a list or list item. Use an indexer to return a single field from this collection. For example, if the collection is 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.
Setting properties of the SPField class and of its inheriting classes requires that the Update method be called for changes to take effect in the database.
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, updates the title, default value, and description for a field.
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