I\'m a beginner in programming, and I was wondering what the right way is to download files in UWP I now use this, but it only works like 50% of the time:
pu
There are two ways to do it.
First one is to use HttpClient as you do (this works well with small files)
Second one is to use BackgroundDownloader Class. That's recommended way
private async void StartDownload_Click(object sender, RoutedEventArgs e)
{
try
{
Uri source = new Uri(inputURL);
StorageFile destinationFile = await KnownFolders.PicturesLibrary.CreateFileAsync(
title.Text, CreationCollisionOption.GenerateUniqueName);
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
// Attach progress and completion handlers.
HandleDownloadAsync(download, true);
}
catch (Exception ex)
{
LogException("Download Error", ex);
}
}