[英]how to download exe files in vb.net (Visual Studio 2015)
I try make one program for download one .exe file and run for help in my job. 我尝试制作一个程序来下载一个.exe文件,然后运行以寻求帮助。 But idk how to make this, i'm new in VB.
但是idk如何做到这一点,我在VB中是新手。
I am using this code, as shown in the Visual Basic document reference : 我正在使用此代码,如Visual Basic文档参考中所示 :
My.Computer.Network.DownloadFile _
("http://www.cohowinery.com/downloads/WineList.txt", _
"C:\Documents and Settings\All Users\Documents\WineList.txt")
But when I try to download an .exe file, the entire file doesn't complete and I the file is only 1 kb after download. 但是,当我尝试下载.exe文件时,整个文件未完成,下载后我只有1 kb。
The webclient should be the way to go a comment above highlights that too. Webclient应该是上面注释的一种方式,这也突出了这一点。
This is an example from another question: 这是另一个问题的示例:
Either use sync method: 使用同步方法:
public void DownloadFile()
{
using(var client = new WebClient())
{
client.DownloadFile(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Or use new async-await approach: 或使用新的异步等待方法:
public async Task DownloadFileAsync()
{
using(var client = new WebClient())
{
await client.DownloadFileTaskAsync(new Uri("http://www.FileServerFullOfFiles.net/download/test.exe"), "test.exe");
}
}
Then call this method like this: 然后像这样调用此方法:
await DownloadFileAsync();
Open up the .exe file you are trying to download in a text editor like NotePad. 在文本编辑器(如NotePad)中打开要尝试下载的.exe文件。 Odds are what is being downloaded is an HTML page showing some kind of error message like
404 not found
. 奇怪的是,正在下载的HTML页面显示出
404 not found
类似404 not found
类的错误消息。
Another possibility might be that AntiVirus software is moving the original EXE into quarantine and replacing it with a Quarantine MetaData file. 另一种可能是AntiVirus软件将原始EXE移入了隔离区,并用隔离区MetaData文件替换了它。
If the file does actually contain binary content your connection could be getting interrupted but odds are if this happened an exception would be thrown. 如果文件确实包含二进制内容,则您的连接可能会中断,但如果发生这种情况,则可能会引发异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.