Share via


File.CopyTo method

Copies the file to the destination URL. Server must overwrite an existing file of the same name if bOverwrite is true.

Namespace:  Microsoft.SharePoint.Client
Assembly:  Microsoft.SharePoint.Client (in Microsoft.SharePoint.Client.dll)

Syntax

'Declaration
Public Sub CopyTo ( _
    strNewUrl As String, _
    bOverWrite As Boolean _
)
'Usage
Dim instance As File
Dim strNewUrl As String
Dim bOverWrite As Boolean

instance.CopyTo(strNewUrl, bOverWrite)
public void CopyTo(
    string strNewUrl,
    bool bOverWrite
)

Parameters

  • strNewUrl
    Type: System.String

    Specifies the destination URL.

    It must not be a null reference (Nothing in Visual Basic). It must be a URL of relative or absolute form.

  • bOverWrite
    Type: System.Boolean

    Specifies whether a file with the same name is overwritten.

Exceptions

Exception Condition
[Microsoft.SharePoint.SPDuplicateValuesFoundException]

List item could not be updated because duplicate values were found for one or more field(s) in the list. Error code: - 2130575169.

[Microsoft.SharePoint.SPFileCheckOutException]

File is not checked out. Error code: -2147024738.

[Microsoft.SharePoint.SPFileCheckOutException]

File is already checked out to a user other than the current user. Error code: -2130575306.

[Microsoft.SharePoint.SPFileLockException]

File is not locked. Error code: -2147024729.

[Microsoft.SharePoint.SPFileLockException]

Operation timed out. Error code: -2147023436.

[Microsoft.SharePoint.SPFileLockException]

A user other than the current user has a shared lock on the file. Error code: -2147018894.

[Microsoft.SharePoint.SPFileLockException]

A user other than the current user has an exclusive lock on the file. Error code: -2147018887.

[Microsoft.SharePoint.SPInvalidLookupValuesException]

List item could not be updated because invalid lookup values were found for one or more field(s) in the list. Error code: -2130575159.

[System.ArgumentException]

The URL must refer to a location within the current site collection. Error code: -2147024809.

[System.UnauthorizedAccessException]

The current user has insufficient permissions. Error code: -2147024891.

See also

Reference

File class

File members

Microsoft.SharePoint.Client namespace