Reputation: 5298
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. 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
Additional information: An exception occurred during a WebClient request.
What am I missing?
Upvotes: 0
Views: 15500
Reputation: 151588
The WebException has an InnerException, which will say:
Access to the path C:\Folder is denied.
Write to a file, not a folder as @JonSkeet mentioned.
Upvotes: 2