예제 #1
0
        /// <summary>
        /// Copies the contents of the given <see cref="IStorageFile"/> into the provided new <see cref="IStorageFile"/>.
        /// </summary>
        /// <param name="file">The existing file whose contents should be read.</param>
        /// <param name="destination">A new, empty file with write access, where the contents of <paramref name="file"/> will be copied.</param>
        public static async Task CopyContentsAsync(this IStorageFile file, IStorageFile destination)
        {
            using (var readFile = await file.OpenFileAsync(FileOpenMode.Read))
            {
                using (var readStream = readFile.GetReadStream())
                {
                    using (var writeFile = await destination.OpenFileAsync(FileOpenMode.ReadWrite))
                    {
                        using (var writeStream = writeFile.GetWriteStream())
                        {
                            await readStream.CopyToAsync(writeStream);

                            await writeStream.FlushAsync();
                        }
                    }
                }
            }
        }