Home > OS >  Directory.GetAccesControll(); Not Working
Directory.GetAccesControll(); Not Working

Time:01-29

I'm trying to create a simple Windows Forms Application that allows to lock and unlock a folders access by providing a path from file explorer. I know what I need to do to create this app but this line of code is getting an error:

 DirectorySecurity s1 = Directory.GetAccessControl(path);

The error states, 'Directory' does not contain definition for 'GetAccessControl'

I am using the namespaces:

using System.Security.AccessControl;
using System.IO; 

Is there anyone who would know how to fix this error from happening or possibly know how to use an alternative to the GetAccessControl(); Method?

I tried using other ways of adding the GetAccessControl(); method into the code, but I had no luck.

CodePudding user response:

You just need to get an instance of DirectoryInfo.

System.IO.DirectoryInfo directoryInfo = new DirectoryInfo(path);
System.Security.AccessControl.DirectorySecurity s1 = directoryInfo.GetAccessControl();
  • Related