[英]Simple Webclient.DownloadFile not Working
Just started using Windows Forms and although the documentation and info on Google seems pretty simple, I can't get my c# Windows Form app to download a file. 刚刚开始使用Windows Forms,虽然Google上的文档和信息看起来很简单,但我无法通过我的c#Windows Form应用程序下载文件。 Here's my code:
这是我的代码:
string remoteUri = "http://mysite.com/file.txt";
string fileName = @"C:\Folder";
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(remoteUri, fileName);
I have confirmed that the link is active and if I type it into a browser it starts the download and that the folder exists on my computer. 我已确认该链接处于活动状态,如果我将其键入浏览器,则会启动下载并且该文件夹存在于我的计算机上。 When I click the button that triggers this event, I get the following error:
当我单击触发此事件的按钮时,出现以下错误:
An unhandled exception of type 'System.Net.WebException' occurred in System.dll System.dll中出现未处理的“System.Net.WebException”类型异常
Additional information: An exception occurred during a WebClient request. 附加信息:WebClient请求期间发生异常。
What am I missing? 我错过了什么?
The WebException has an InnerException, which will say: WebException有一个InnerException,它会说:
Access to the path C:\\Folder is denied.
访问路径C:\\ Folder被拒绝。
Write to a file, not a folder as @JonSkeet mentioned. 写入文件,而不是@JonSkeet提到的文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.