【发布时间】:2018-09-01 01:33:03
【问题描述】:
我有一个 UWP 应用,可以从网站下载 pdf 文件到ApplicationData.Current.LocalFolder,但是当我使用资源管理器打开下载的文件时,它的大小始终为 0KB,无法打开。
对于下载,我使用了以下代码:
using System.Diagnostics;
using Windows.Networking.BackgroundTransfer;
using Windows.Storage;
private async void Button_Click(object sender, RoutedEventArgs e)
{
try
{
Uri source = new Uri("http://www.sachsen.schule/~goethe-gym-auerbach/vplan/VertretungsplanMo.pdf");
StorageFile destinationFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("VertretungsplanMo.pdf", CreationCollisionOption.ReplaceExisting);
BackgroundDownloader downloader = new BackgroundDownloader();
DownloadOperation download = downloader.CreateDownload(source, destinationFile);
Debug.WriteLine("Download successfull");
}
catch (Exception ex)
{
Debug.WriteLine("Download error. Exception: " + ex);
}
}
虽然我从未收到下载错误,但文件始终为 0 KB。
【问题讨论】: