我正在尝试制作一个用于从我的网站下载文件的用户界面。该站点有 zip 文件,需要将这些文件下载到用户输入的目录中。但是,我无法成功下载该文件,它只是从临时文件夹中打开。
Code:
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
e.Cancel = true;
string filepath = null;
filepath = textBox1.Text;
WebClient client = new WebClient();
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(e.Url, filepath);
}
完整源代码:http://en.paidpaste.com/LqEmiQ http://en.paidpaste.com/LqEmiQ
我的程序完全按照您的要求执行,没有提示或任何内容,请参阅以下代码。
此代码将创建所有必需的目录(如果它们尚不存在):
Directory.CreateDirectory(C:\dir\dira\dirb); // This code will create all of these directories
此代码会将给定文件下载到给定目录(在上一个代码段创建该文件之后:
private void install()
{
WebClient webClient = new WebClient(); // Creates a webclient
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed); // Uses the Event Handler to check whether the download is complete
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged); // Uses the Event Handler to check for progress made
webClient.DownloadFileAsync(new Uri("http://www.com/newfile.zip"), @"C\newfile.zip"); // Defines the URL and destination directory for the downloaded file
}
因此,使用这两段代码,您可以创建所有目录,然后告诉下载程序(这不会提示您将文件下载到该位置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)