I can reproduce this if I specify, as seems to be the case in your example, a folder name rather than a file name the destination. Supply a file name instead.
As an aside; if I look at the InnerException
, it tells me that the problem relates to the file path:
using(var client = new WebClient()) { try { client.DownloadFile( "http://stackoverflow.com/questions/8033619/an-exception-occurred-durning-a-webclient-request-c-sharp-asp-net/8033687#8033687", @"j:\MyPath"); } catch (Exception ex) { while (ex != null) { Console.WriteLine(ex.Message); ex = ex.InnerException; } } }
Which gives:
An exception occurred during a WebClient request. Access to the path 'j:\MyPath' is denied.
If I change it to a file, it works fine:
client.DownloadFile( "http://stackoverflow.com/questions/8033619/an-exception-occurred-durning-a-webclient-request-c-sharp-asp-net/8033687#8033687", @"j:\MyPath\a.html");