简体   繁体   中英

Creating a Folder in C#, Applying Permissions, But access is still DENIED?

So I have this code below that creates a Directory and gives ASPNET permissions on the folder created. But when I run The Webclient.Downloadfile method, it says the folder created is still access denied..

Ive also just created a folder on C:/ and tried applying permissions my self and see what I get. But I still get access denied.

Can anyone help?

 DirectoryInfo di = Directory.CreateDirectory(path);
                    System.Security.AccessControl.DirectorySecurity dSec = di.GetAccessControl();
                    dSec.AddAccessRule(new System.Security.AccessControl.FileSystemAccessRule(@"LV38PCE00081461\ASPNET", System.Security.AccessControl.FileSystemRights.FullControl, System.Security.AccessControl.AccessControlType.Allow));
                    di.SetAccessControl(dSec);

Here is the Webclient.Download File Method im calling.
folderID is the the directory Exp: "C:\\hello"

WebClient webClient = new WebClient();
webClient.DownloadFile(new Uri(reader.Value), folderID);
Console.WriteLine(folderID + " File Downloaded");

This Method above is what gives the Access denied.

On a Side note: This is a CONSOLE application... Its not a webpage or a web service.

Is folderID the file that the data should be downloaded to or the folder that you want it downloaded to? It should be the file.

public void DownloadFile( Uri address, string fileName )

Parameters

address Type: System.Uri The URI specified as a String, from which to download data.

fileName Type: System.String The name of the local file that is to receive the data.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM