[英]Granting full permissions to everyone on newly created folder from within c#
Im saving images from a URL list but trying to duplicate the folder structure locally. 我从URL列表中保存图像,但尝试在本地复制文件夹结构。
I parse the URL to give me the folder structure I want : 我解析URL,以获取所需的文件夹结构:
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: 我的本地基本文件夹是
mydocs/site/images
我将url字符串分割开了,并且能够使用以下命令递归创建正确的文件夹结构:
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."
“ System.UnauthorizedAccessException:拒绝访问路径'mydocs \\ images \\ test \\ test1 \\ test \\ 2 \\ 3m'。”
So I am guessing that I need to create a step in the CREATEDIRECTORY area where I immediately grant access to that folder. 所以我想我需要在CREATEDIRECTORY区域中创建一个步骤,在该区域中我立即授予对该文件夹的访问权限。
Is there an easy way to do this? 是否有捷径可寻?
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); 在这里: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" 当它应该已经出现在“ C:\\ mydocs \\ images \\ test \\ test2 \\ theimagefilename.jpg”时,finalLocalFolder最终会类似于:“ C:\\ mydocs \\ images \\ test \\ test2”
Stupid moment. 愚蠢的时刻。 Sorry.
抱歉。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.