Click or drag to resize
GDStorageFileCopyAsync Method (IGDStorageFolder, String, NameCollisionOption)
Creates a copy of the file in the specified folder and renames the copy. This method also specifies what to do if a file with the same name already exists in the destination folder.

Namespace:  GD
Assembly:  GD (in GD.dll) Version: 255.255.255.255
Syntax
public IAsyncOperation<GDStorageFile> CopyAsync(
	IGDStorageFolder destinationFolder,
	string desiredNewName,
	NameCollisionOption option
)

Parameters

destinationFolder
Type: GDIGDStorageFolder
The destination folder where the copy of the file is created.
desiredNewName
Type: SystemString
The new name for the copy of the file created in the destinationFolder.
option
Type: Windows.StorageNameCollisionOption
One of the enumeration values that determines how to handle the collision if a file with the specified desiredNewName already exists in the destination folder.

Return Value

Type: IAsyncOperationGDStorageFile
When this method completes, it returns a GDStorageFile that represents the copy of the file created in the destinationFolder.

Implements

IGDStorageFileCopyAsync(IGDStorageFolder, String, NameCollisionOption)
Exceptions
ExceptionCondition
AccessDeniedException(C# equivalent: System.UnauthorizedAccessException) Secure storage was remotely wiped.
Exception Name you specify is invalid. To handle all the ways the specified name could be invalid, you must catch all of these exceptions:
E_FAIL
ERROR_INVALID_NAME
ERROR_ALREADY_EXISTS
ERROR_INVALID_PARAMETER
Remarks
This method uses the FailIfExists value from the NameCollisionOption enumeration by default. That is, this method raises an exception if a file with the same name already exists in the destination folder. If you want to handle a file name collision in a different way, call the CopyAsync(IGDStorageFolder, String, NameCollisionOption) method.
Examples
The following example shows how to get the folder that has the specified absolute path in the SDK secure storage.
using GD;

...

    // Get the app's secure folder.
    GDStorageFolder secureFolder = GDWindows.Instance.SecureFolder;

    // Create a sample file in the secure folder.
    string newFileName = "test.txt";
    GDStorageFile newFile = await tempFolder.CreateFileAsync(newFileName);

    // Get folder from secure folder
    GDStorageFolder folder = secureFolder.GetFolderAsync("folder");

    // Specify a new name for the copied file.
    string renamedFileName = "renamed_test.txt";

    // Copy the file to the destination folder and rename it.
    // Replace the existing file if the file already exists.
    GDStorageFile copiedFile =
        await newFile.CopyAsync(folder,
            renamedFileName, NameCollisionOption.ReplaceExisting);
See Also