SpoiledTechie.com
SpoiledTechie.com

Reputation: 10735

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.

Upvotes: 0

Views: 3408

Answers (1)

Brett Widmeier
Brett Widmeier

Reputation: 1077

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.

Upvotes: 1

Related Questions