Reputation: 4711
Im saving images from a URL list but trying to duplicate the folder structure locally.
I parse the URL to give me the folder structure I want :
Example:
URL = www.site.com/images/folder1/folder2/image
My local base folder is mydocs/site/images
I split the url string up and am able to recursively create the proper folder structure using:
if (!Directory.Exists(finalLocalFolder))
{
DirectoryInfo di = Directory.CreateDirectory(finalLocalFolder);
}
Everything works great UNTIL I try and save the image to the folder using :
WebClient webClient = new WebClient();
webClient.DownloadFile(remoteUrl, finalLocalFolder);
In which case, I am told that access to that folder is denied.
"System.UnauthorizedAccessException: Access to the path 'mydocs\images\test\test1\test\2\3m' is denied."
So I am guessing that I need to create a step in the CREATEDIRECTORY area where I immediately grant access to that folder.
Is there an easy way to do this?
Upvotes: 0
Views: 876
Reputation: 4711
I can close this if you would like - but just to put up what my problem was... here it is:
In here: webClient.DownloadFile(remoteUrl, finalLocalFolder);
finalLocalFolder was ending up something like: "C:\mydocs\images\test\test2" when IT SHOULD HAVE BEEN "C:\mydocs\images\test\test2\theimagefilename.jpg"
Stupid moment. Sorry.
Upvotes: 1