Share via


SPFile.Delete Method

Deletes the file object.

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(SPFileLockException),  _
    ErrorCode := , Condition := "There is an exclusive lock on the file")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "5", Condition := "File cannot be found.",  _
    ErrorType := GetType(FileNotFoundException))> _
<ClientCallableMethodAttribute(Name := "DeleteObject", RemoveThisObjectFromParentCollection := True)> _
<ClientCallableExceptionConstraintAttribute(FixedId := "1", Condition := "Lack of permissions to perform the operation.",  _
    ErrorType := GetType(UnauthorizedAccessException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "2", ErrorType := GetType(SPFileCheckOutException),  _
    ErrorCode := , Condition := "File is checked out to somebody else")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "4", ErrorType := GetType(SPFileLockException),  _
    ErrorCode := , Condition := "There is a shared lock on the file")> _
Public Sub Delete
'Usage
Dim instance As SPFile

instance.Delete()
[ClientCallableExceptionConstraintAttribute(FixedId = "3", ErrorType = typeof(SPFileLockException), 
    ErrorCode = , Condition = "There is an exclusive lock on the file")]
[ClientCallableExceptionConstraintAttribute(FixedId = "5", Condition = "File cannot be found.", 
    ErrorType = typeof(FileNotFoundException))]
[ClientCallableMethodAttribute(Name = "DeleteObject", RemoveThisObjectFromParentCollection = true)]
[ClientCallableExceptionConstraintAttribute(FixedId = "1", Condition = "Lack of permissions to perform the operation.", 
    ErrorType = typeof(UnauthorizedAccessException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "2", ErrorType = typeof(SPFileCheckOutException), 
    ErrorCode = , Condition = "File is checked out to somebody else")]
[ClientCallableExceptionConstraintAttribute(FixedId = "4", ErrorType = typeof(SPFileLockException), 
    ErrorCode = , Condition = "There is a shared lock on the file")]
public void Delete()

Exceptions

Exception Condition
SPException

An error occurred while deleting the file.

Remarks

If the file does not exist, the Delete method silently fails and does not throw an exception.

See Also

Reference

SPFile Class

SPFile Members

Microsoft.SharePoint Namespace