GRW
GRW

Reputation: 615

Downloading from website error - Could not find a part of the path

I am trying to create a quick fix for a problem I am having. All I need to do is download a file from my website to a local computer.

I have a website using ASP.NET and C# and I have added the code below to a button click to download a file:

WebClient webClient = new WebClient(); webClient.DownloadFile("http://www.mysite.com/myfile.ext", @"C:\test\myfile.ext");

which produces the error in the title:

Could not find a part of the path 'C:\test\myfile.ext'.

The directory does exist on my computer.

From what I have read this appears to be a permissions issue on the local computer. I have added full permissions on that directory for the NETWORK SERVICE user as I am running Windows 7. I also have a user that is running XP so I believe the user there would be ASPNET.

Needless to say none of this has worked and allowed me to download the file. I'm a little out of my element here so I'm not sure what to do. It could be that I'm on the right track and just missed something obvious, or maybe I'm way off base.

Anyone have some guidance for me?

EDIT

The more I think about this, I can't help but think there's a better way to do this.

I've downloaded from websites before without ever needing to deal with permissions, so what would be a better simple approach? What am I missing here?

ANSWER

Thanks, I found exactly what I needed from Hari's responses below.

Upvotes: 0

Views: 2076

Answers (2)

user191966
user191966

Reputation:

The user running the application pool used by your website needs to be given permissions to read that file. So, goto IIS > app pools > find the one for your website > the one that's under identity.

Upvotes: 1

Tomek
Tomek

Reputation: 3279

Check the application pool identity type to make sure you are granting permission to the correct user, see this website for more details.

Upvotes: 0

Related Questions