Lamloumi Afif
Lamloumi Afif

Reputation: 9081

Using Web.Net.WebClient to download a file

ffI am beginner in the download files and directories with c# using Web.Net.WebClient. I tried this snippet to download a file:

 Upload.Models.FichierModels fichier = new FichierModels();
 WebClient client = new WebClient();
 try
 {
  client.DownloadFile(new Uri(fichier.GetFichierUrlById(_id)), "fichier");
 }
 catch { }

but I got this exception:

Access to the path 'C: \ \ Program Files (x86) \ \ IIS Express \ \ file' is denied

What is the cause of this exception? How can I fix my code?

Upvotes: 2

Views: 942

Answers (1)

Freelancer
Freelancer

Reputation: 9064

You will have to find out from the application pool for the website what is the identity it is running under.

By default this is Application Pool Identity.

And then you will have to grant that the correct permissions.

Like Follows:

SOLUTION

  1. Start > Administrative Tools > Internet Information Services (IIS) Manager

  2. Expand the machine node > expand Sites

  3. Locate GFI MailArchiver virtual directory

  4. Right-click GFI MailArchiver virtual directory > Edit Permissions...

    select Security tab

  5. Add Domain Admins and Domain Users with Full Control Permissions

Referance:

http://kb.gfi.com/articles/Skynet_Article/Error-Access-to-path-C-Program-Files-X86-GIF-MailArchiver-ASPNET-profiles-username-is-denied-when-loading-web-UI

Hope Its Helpful.

Upvotes: 1

Related Questions