0

好的,所以我对编程还很陌生,被告知只需启动几个项目和谷歌/询问我是否需要 hep 所以我在这里,我正在制作一个程序,它将从互联网下载和运行文件,当我运行发布应用程序时我收到此错误http://gyazo.com/7b017f0ed550af3b86b24ad480db8fe8所以我按详细信息,它给了我这个很长的错误报告http://pastebin.com/Ag7u9gBZ我似乎没有足够的知识来阅读和调试它,我很困惑,从我所看到的它与 system.io 和 webclient 和路径或我不知道的东西有关。

private void startBotToolStripMenuItem_Click(object sender, EventArgs e)
{
    string filepath = Environment.GetEnvironmentVariable("AppData") + "\\Downloaded Files\\" + "Minecraft.exe";
    string direct_exe_from_url = "http://rs542p2.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=1764003915&filename=Minecraft.exe&cookie=F2CB284BDC9920808D8494CA4EB46F0935AB22D79EC69D6D130C21FB6AD2A0A1EB413347302A46C5FB1A39599DF740D6&directstart=1";

    WebClient wc = new WebClient();
    wc.DownloadFile(direct_exe_from_url, filepath);

    Process.Start(filepath);
}
4

1 回答 1

0

你得到一个System.IO.DirectoryNotFoundException所以我猜这个:C:\Users\Owner\AppData\Roaming\Downloaded Files\目录不存在。

您可以Directory.CreateDirectory在将下载的文件放入之前使用该方法创建目录,例如:

string directoryPath = Environment.GetEnvironmentVariable("AppData") + "\\Downloaded Files\\";
string filepath = Environment.GetEnvironmentVariable("AppData") + "\\Downloaded Files\\" + "Minecraft.exe";

if (!Directory.Exists(directoryPath)) 
{
     Directory.CreateDirectory(directoryPath);
}

string direct_exe_from_url = "http://rs542p2.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=1764003915&filename=Minecraft.exe&cookie=F2CB284BDC9920808D8494CA4EB46F0935AB22D79EC69D6D130C21
//Rest of your code
于 2013-04-17T22:56:34.177 回答