I get this error message when I try to copy a big file ( ~500 MB):
Error HRESULT E_FAIL has been returned from a call to a COM component. HResult: -2147467259
this is the code I use to copy a file:
await file.CopyAsync(storageFolder, name, NameCollisionOption.GenerateUniqueName);
Thanks to the developer behind it, it is not very informative.
So how to fix this issue? thank.
(I'm testing it in Windows Phone 8.1)
I tested with a 1.5 GB file and was able to replicate the exception. Setting the internal buffer size manually seems to solve the problem, but be aware of how that affects the application. Read under the Buffer section on MSDN on dealing with large data sets.
The CreateNewFileAsync() method simply creates a new file :)
Best of luck and happy coding.
var folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
var file = await folder.GetFileAsync("largeFile.txt");
StorageFolder tempFolder = ApplicationData.Current.TemporaryFolder;
// Exception
if (file != null)
{
StorageFile copiedFile = await file.CopyAsync(tempFolder, "copied.txt", NameCollisionOption.GenerateUniqueName);
}
// Setting the internal buffer to 1024
// Be aware- from MSDN: However, this buffer is allocated on the large object heap
// and could potentially degrade garbage collection performance.
// You should only use large buffer sizes if it will noticeably improve the performance of your app.
var newFile = await CreateNewFileAsync();
using (Stream ss = await file.OpenStreamForReadAsync())
using (Stream sd = await newFile.OpenStreamForWriteAsync())
{
await ss.CopyToAsync(sd, 1024);
var fileProps = await file.GetBasicPropertiesAsync();
var size = fileProps.Size;
}