Question

i have button, on a click of which i want to download the file on the local pc, i am using webclient.downloadfile(), but i am getting the below error:

Access to the path 'C:\Windows\SysWOW64\inetsrv\ms-banner.gif' is denied.

i am using below code to download file:

WebClient client = new WebClient();
        client.DownloadFile(new Uri("http://www.contoso.com/library/homepage/images/ms-banner.gif"), "ms-banner.gif");

i dont understand why its fetching the file from local server, as i have already stated the remote uri

Was it helpful?

Solution

It's fetching the file from the remote server but trying to save it in the current directory because you have only specified a relative filename as second argument: "ms-banner.gif". And it seems that the account you are running your application under doesn't have permission to write to the current working directory which happens to be C:\Windows\SysWOW64\inetsrv.

So you have basically 2 possibilities:

  • Modify the account you are running your application under and grant it permissions to write to this directory
  • Specify another location (as an absolute path) to save the file to where the account you are running your application under has write permissions.

OTHER TIPS

contoso.com redirects to microsoft.com... the path you have there in the URL does not exist and you won't be able to download it. I'm not sure why it's trying to go to your local machine, but have you tried some other image on some other website? Like http://i.cdn.turner.com/cnn/.e/img/3.0/global/header/hdr-main.gif for example?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top