gpt4 book ai didi

c# - 如何从网站下载 .EXE 文件?

转载 作者:行者123 更新时间:2023-11-30 20:23:59 25 4
gpt4 key购买 nike

我正在编写一个应用程序,我需要从网站下载一个 exe 文件。我正在使用 Visual Studio Express 2008。

我正在使用以下代码。

private void button1_Click(object sender, EventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadFileAsync(new Uri("http://example.com/images/def.exe"), @"d:\ac\def.exe");
}

下载到D盘Ac文件夹下的def.exe是0字节。

我无法理解为什么会这样。

请帮帮我。

最佳答案

DownloadFileAsync 方法运行异步,这意味着,它会在下载开始后立即返回。如果你想等待它结束,你必须订阅 DownloadFileCompleted 事件。

当然你也可以使用同步方式,像这样:

webClient.DownloadFile(new Uri("http://example.com/images/def.exe"), @"d:\ac\def.exe");           

关于c# - 如何从网站下载 .EXE 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27689565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com