0

When creating an instance of the WebClient class and when trying to download a file at the specified URL, with the specified path of the folder where you want to save the file, an error occurs: Unhandled exception. System.Net.WebException: An exception occurred during a WebClient request.

        static public void DownloadFile()
        {
            WebClient WebClient = new WebClient();
            WebClient.DownloadFile(Config.URL, Config.ImageLink);
        }
  • 1
    Please [edit] the question and provide all the [exception details](https://idownvotedbecau.se/noexceptiondetails/). – 41686d6564 stands w. Palestine Sep 02 '21 at 04:27
  • Does the target download folder actually exist? – Delta Sep 02 '21 at 04:29
  • Naming a variable with the same name as a class makes your code very hard to read. As a reader, I need to ask myself: is `WebClient.DownloadFile` a static method of the `WebClient` class or is an instance method being called through the `WebClient` variable – Flydog57 Sep 02 '21 at 04:31

1 Answers1

0

Add appropiate folder permissions(write permissions) for user that created the process.

Or you can Impersonate with user account that have write permissions on the folder.

Impersonate users in C#
How do you do Impersonation in .NET? stackoverflow.com

Joma
  • 3,520
  • 1
  • 29
  • 32