好吧,所以我对编程还很陌生,并被告知如果我需要帮助,请启动一些项目和google / ask,所以我在这里,我正在制作一个程序,可以从互联网下载并运行文件,当我运行发布应用程序时我收到此错误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);
}

===============>>#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

  ask by D4rk translate from so

未解决问题?本站智能推荐: