Compartilhar via


SPFile.MoveTo Method (String, SPMoveOperations)

Moves the file to the specified destination URL based on the type of operation that is specified.

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

Syntax

'Declaration
<ClientCallableExceptionConstraintAttribute(FixedId := "8", ErrorType := GetType(SPDuplicateValuesFoundException),  _
    ErrorCode := , Condition := "The list item could not be updated because duplicate values were found for one or more field(s) in the list")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "7", ErrorType := GetType(SPFileLockException),  _
    ErrorCode := , Condition := "The file is not locked")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "4", ErrorType := GetType(SPFileLockException),  _
    ErrorCode := , Condition := "There is an exclusive lock on the file")> _
<ClientCallableAttribute> _
<ClientCallableExceptionConstraintAttribute(FixedId := "9", ErrorType := GetType(SPInvalidLookupValuesException),  _
    ErrorCode := , Condition := "The list item could not be updated because because invalid lookup values were found for one or more field(s) in the list")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "1", ErrorType := GetType(ArgumentException),  _
    Condition := "URL MUST refer to the current Site Collection")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "6", ErrorType := GetType(SPFileLockException),  _
    ErrorCode := , Condition := "The operation timed out")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "13", ErrorType := GetType(UnauthorizedAccessException),  _
    Condition := "Lack of permission to perform the operation")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "3", ErrorType := GetType(SPFileCheckOutException),  _
    ErrorCode := , Condition := "The file is not checked out")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "2", ErrorType := GetType(SPFileCheckOutException),  _
    ErrorCode := , Condition := "File already checked out")> _
<ClientCallableExceptionConstraintAttribute(FixedId := "5", ErrorType := GetType(SPFileLockException),  _
    ErrorCode := , Condition := "There is a shared lock on the file")> _
Public Sub MoveTo ( _
    newUrl As String, _
    flags As SPMoveOperations _
)
'Usage
Dim instance As SPFile
Dim newUrl As String
Dim flags As SPMoveOperations

instance.MoveTo(newUrl, flags)
[ClientCallableExceptionConstraintAttribute(FixedId = "8", ErrorType = typeof(SPDuplicateValuesFoundException), 
    ErrorCode = , Condition = "The list item could not be updated because duplicate values were found for one or more field(s) in the list")]
[ClientCallableExceptionConstraintAttribute(FixedId = "7", ErrorType = typeof(SPFileLockException), 
    ErrorCode = , Condition = "The file is not locked")]
[ClientCallableExceptionConstraintAttribute(FixedId = "4", ErrorType = typeof(SPFileLockException), 
    ErrorCode = , Condition = "There is an exclusive lock on the file")]
[ClientCallableAttribute]
[ClientCallableExceptionConstraintAttribute(FixedId = "9", ErrorType = typeof(SPInvalidLookupValuesException), 
    ErrorCode = , Condition = "The list item could not be updated because because invalid lookup values were found for one or more field(s) in the list")]
[ClientCallableExceptionConstraintAttribute(FixedId = "1", ErrorType = typeof(ArgumentException), 
    Condition = "URL MUST refer to the current Site Collection")]
[ClientCallableExceptionConstraintAttribute(FixedId = "6", ErrorType = typeof(SPFileLockException), 
    ErrorCode = , Condition = "The operation timed out")]
[ClientCallableExceptionConstraintAttribute(FixedId = "13", ErrorType = typeof(UnauthorizedAccessException), 
    Condition = "Lack of permission to perform the operation")]
[ClientCallableExceptionConstraintAttribute(FixedId = "3", ErrorType = typeof(SPFileCheckOutException), 
    ErrorCode = , Condition = "The file is not checked out")]
[ClientCallableExceptionConstraintAttribute(FixedId = "2", ErrorType = typeof(SPFileCheckOutException), 
    ErrorCode = , Condition = "File already checked out")]
[ClientCallableExceptionConstraintAttribute(FixedId = "5", ErrorType = typeof(SPFileLockException), 
    ErrorCode = , Condition = "There is a shared lock on the file")]
public void MoveTo(
    string newUrl,
    SPMoveOperations flags
)

Parameters

  • newUrl
    Type: System.String

    A string that specifies the destination URL.

  • flags
    Type: Microsoft.SharePoint.SPMoveOperations

    An enumeration value that specifies the type of move operation; for example, whether to complete the operation when supporting files are absent, or whether to overwrite a file with the same name.

Exceptions

Exception Condition
ArgumentException

The value of the flags is not valid.

Remarks

The flags can only be set to BypassApprovePermission, Overwrite, AllowBrokenThickets, or the result of a bitwise OR operation between them.

See Also

Reference

SPFile Class

SPFile Members

MoveTo Overload

Microsoft.SharePoint Namespace