Share via


SPField.Delete Method

Deletes the field.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableExceptionConstraintAttribute(FixedId := "3", ErrorType := GetType(InvalidOperationException),  _
    Condition := "The field cannot be deleted because it does not allow deletion.")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "8", ErrorCode := , Condition := "The field cannot be deleted because it is a read only field in the list.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "accessdenied", Condition := "Lack of permissions to perform the operation.",  _
    ErrorType := GetType(UnauthorizedAccessException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "5", ErrorCode := , Condition := "The field cannot be deleted because it is inherited from the list's base type.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "2", ErrorType := GetType(ArgumentException),  _
    Condition := "The field cannot be deleted because it does not exist in the list.")> _
<ClientCallableMethodAttribute(Name := "DeleteObject", RemoveThisObjectFromParentCollection := True)> _
<ClientCallableExceptionConstraintAttribute(FixedId := "7", ErrorCode := , Condition := "The field cannot be deleted because it is a sealed field in the list.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "1", ErrorType := GetType(SPException),  _
    Condition := "The field cannot be deleted because it is a primary lookup field with dependent lookups OR a read only field in the list.",  _
    ErrorCode := )> _
<ClientCallableExceptionConstraintAttribute(FixedId := "thresholdexceeded", ErrorCode := , Condition := "Operation exceeds the list view threshold enforced by the administrator.",  _
    ErrorType := GetType(SPQueryThrottledException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "6", ErrorCode := , Condition := "The field cannot be deleted because it is a hidden field in the list.",  _
    ErrorType := GetType(SPException))> _
Public Sub Delete
'Usage
Dim instance As SPField

instance.Delete()
[ClientCallableExceptionConstraintAttribute(FixedId = "3", ErrorType = typeof(InvalidOperationException), 
    Condition = "The field cannot be deleted because it does not allow deletion.")]
[ClientCallableExceptionConstraintAttribute(FixedId = "8", ErrorCode = , Condition = "The field cannot be deleted because it is a read only field in the list.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "accessdenied", Condition = "Lack of permissions to perform the operation.", 
    ErrorType = typeof(UnauthorizedAccessException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "5", ErrorCode = , Condition = "The field cannot be deleted because it is inherited from the list's base type.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "2", ErrorType = typeof(ArgumentException), 
    Condition = "The field cannot be deleted because it does not exist in the list.")]
[ClientCallableMethodAttribute(Name = "DeleteObject", RemoveThisObjectFromParentCollection = true)]
[ClientCallableExceptionConstraintAttribute(FixedId = "7", ErrorCode = , Condition = "The field cannot be deleted because it is a sealed field in the list.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "1", ErrorType = typeof(SPException), 
    Condition = "The field cannot be deleted because it is a primary lookup field with dependent lookups OR a read only field in the list.", 
    ErrorCode = )]
[ClientCallableExceptionConstraintAttribute(FixedId = "thresholdexceeded", ErrorCode = , Condition = "Operation exceeds the list view threshold enforced by the administrator.", 
    ErrorType = typeof(SPQueryThrottledException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "6", ErrorCode = , Condition = "The field cannot be deleted because it is a hidden field in the list.", 
    ErrorType = typeof(SPException))]
public void Delete()

Exceptions

Exception Condition
ArgumentException

The field cannot be found.

InvalidOperationException

The field cannot be deleted.

SPException

The field collection containing this field is read-only.

Remarks

This method calls the Delete(String) method to delete the field.

See Also

Reference

SPField Class

SPField Members

Microsoft.SharePoint Namespace