None of these solutions worked for me, or were not complete. Maybe this post was old and newer versions of .NET made it easier? Anyway, the following small code did the job for me so nicely:
static async Task DownloadFile(string url, string filePath)
{
using (var wc = new WebClient())
await wc.DownloadFileTaskAsync(url, filePath);
}
发布评论
评论(7)
检查这个方法,希望有帮助
check this method , hope that helps
请尝试以下代码示例来下载 .pdf 文件。
Please try the Following code sample to download .pdf file.
@赛义德·穆达西尔:
它只是一行:)
它将下载 pdf 文件。 :)
@Syed Mudhasir:
Its just a line :)
It will download pdf files. :)
这些解决方案都不适合我,或者都不完整。也许这篇文章是旧的,新版本的 .NET 让它变得更容易?不管怎样,下面的小代码很好地完成了我的工作:
这里是如何调用该方法的:
None of these solutions worked for me, or were not complete. Maybe this post was old and newer versions of .NET made it easier? Anyway, the following small code did the job for me so nicely:
And here how you can call the method:
确保添加: using System.Net;
Make sure you add: using System.Net;
这对我有用:
This worked for me: