Skip to content

Instantly share code, notes, and snippets.

@Adam--
Created September 15, 2016 13:08
Show Gist options
  • Save Adam--/a45ee0756a00bf24a847e0ddc70b0b72 to your computer and use it in GitHub Desktop.
Save Adam--/a45ee0756a00bf24a847e0ddc70b0b72 to your computer and use it in GitHub Desktop.
Copy a file to a folder using PCLStorage
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);
}
}
}
}
@RobbiewOnline
Copy link

This was useful for me, thanks. I adjusted to return the destinationFile as Task

@wuhuangjia
Copy link

thanks alot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment