Vb.net 如何将My.Computer.FileSystem.CurrentDirectory与My.Computer.Network.DownloadFile一起使用?

Vb.net 如何将My.Computer.FileSystem.CurrentDirectory与My.Computer.Network.DownloadFile一起使用?,vb.net,Vb.net,我试着这样使用它: Public Class Form1 Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click My.Computer.Network.DownloadFile( "http://magicalexample.com/multi.zip", "My.Computer.FileSystem.CurrentDirecto

我试着这样使用它:

Public Class Form1


Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    My.Computer.Network.DownloadFile(
        "http://magicalexample.com/multi.zip", "My.Computer.FileSystem.CurrentDirectory\multi.zip")
    Process.Start("cmd", "/k jar xf multi.zip")
    MsgBox("Done.")
End Sub
End Class
(注意:我搞砸了格式,它在VB中是正确的,不用担心lol)


当我尝试使用update按钮时,它告诉我destinationFileName需要包含一个文件名。它们在一起玩得不是很好吗?My.Computer.FileSystem.CourrentDirectory是一个变量,不会被神奇地解析为字符串。您需要将变量与文件位置连接起来:

My.Computer.Network.DownloadFile("http://magicalexample.com/multi.zip", My.Computer.FileSystem.CurrentDirectory & "\multi.zip")
或者使用以下方法合并目录和文件名:

My.Computer.Network.DownloadFile("http://magicalexample.com/multi.zip", Path.Combine(My.Computer.FileSystem.CurrentDirectory, "multi.zip"))
请注意,由于各种原因,您的示例不起作用。他们需要前面的http://文件,并且该文件必须存在于源位置(不能是404NotFound错误)。此外,您发布的评论中额外的分号似乎表明它甚至不会编译,因此您可能正在运行以前的版本。我创建了一个新项目,并以运行这段代码为例,从主页下载google徽标

My.Computer.Network.DownloadFile("https://www.google.com/images/srpr/logo11w.png", Path.Combine(My.Computer.FileSystem.CurrentDirectory, "logo.png"))

我已经尝试了这两种方法,但它仍然会告诉我“destinationFileName需要包含一个文件名”。这是在DownloadfiLe中发生的,还是在进程的命令提示符下向控制台窗口显示了一条错误消息。开始行?换句话说,是什么给了你信息?正在抛出异常或有东西正在将其写入屏幕?展示你能做的一切在用我的代码更正你的代码后,你能按原样重新复制/粘贴你的代码吗?我有兴趣看到一些东西。Imports System.IO Public Class Form1 Private Sub Button1\u Click(sender作为System.Object,e作为System.EventArgs)处理按钮1。单击My.Computer.Network.DownloadFile(“”,Path.Combine(My.Computer.FileSystem.CurrentDirectory,“multi.zip”))Process.Start(“cmd”,“/k jar xf multi.zip”)MsgBox(“Done.”End子端类验证了它是否需要“http://”,并且它必须存在。本例中的文件在远程服务器上不存在。我运行代码,得到一个404找不到。