Created
September 15, 2016 13:08
-
-
Save Adam--/a45ee0756a00bf24a847e0ddc70b0b72 to your computer and use it in GitHub Desktop.
Copy a file to a folder using PCLStorage
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace com.github.gist.adam-- | |
{ | |
using System.Threading; | |
using PCLStorage; | |
using FileAccess = PCLStorage.FileAccess; | |
public static class PCLStorageExtensions | |
{ | |
public static async void CopyFileTo(this IFile file, IFolder destinationFolder, CancellationToken cancellationToken = default(CancellationToken)) | |
{ | |
var destinationFile = | |
await destinationFolder.CreateFileAsync(file.Name, CreationCollisionOption.ReplaceExisting, cancellationToken); | |
using (var outFileStream = await destinationFile.OpenAsync(FileAccess.ReadAndWrite, cancellationToken)) | |
using (var sourceStream = await file.OpenAsync(FileAccess.Read, cancellationToken)) | |
{ | |
await sourceStream.CopyToAsync(outFileStream, 81920, cancellationToken); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This was useful for me, thanks. I adjusted to return the destinationFile as Task