1

I have an image in one of my folders, using webclient i am trying to download the image.

using (WebClient webClient = new WebClient())
{
 webClient.DownloadFile(SessionManager.Current.ImagePath,SessionManager.Current.ImageName);
}

Here SessionManager.Current.ImagePath has something like

"D:\\TFS\\MyProject\\MyProject1.5\\07 Construction\\01 SourceCode\\.NET\\MyProject1.5\\PanelImages\\20\\636403789911551848.PNG"

But all i get is an exception saying the folder is not accessible with the following message.

System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\IIS Express\636403764977345693.PNG' is denied.

I even tried unchecking the readonly for the PanelImages folder in vain(It keeps reverting back to readonly).

I wonder why it is accessing Program Files (x86)\IIS Express\ when the path i provided is different?

can someone tell me wheere i might be going wrong?

WorksOnMyLocal
  • 1,617
  • 3
  • 23
  • 44
  • 1
    There seems to be some confusion here. *where* is this code running, and what's the overall goal? At the moment it looks like you're trying to download an image *onto* the server. – Damien_The_Unbeliever Sep 07 '17 at 05:44
  • @Damien_The_Unbeliever the code is running on localhost server, the goal is to download the image present in the server folder onto the client's system. i.e. when hosted in IIS the image file will be in the IIS application folder and should be downloaded into the client's downloads folder. – WorksOnMyLocal Sep 07 '17 at 09:22
  • Yeah, you don't use the `WebClient` for that. You provide the file as a HTTP response and it's the user's browser that then takes over control, prompts the user for where they want to save the file, etc. – Damien_The_Unbeliever Sep 07 '17 at 14:20

0 Answers0