'An exception occurred during a WebClient request" while using C# ASP.NET

后端 未结 6 1690
生来不讨喜
生来不讨喜 2021-02-05 04:20

So, I have built an auto update program to my program.

The code that is running in here is:

new WebClient().DownloadFile(\"XXXX\", checkingfolder.Select         


        
6条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 04:57

    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");
    

提交回复
热议问题