Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Directory.GetAccesControll(); Not Working

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

You just need to get an instance of DirectoryInfo.

System.IO.DirectoryInfo directoryInfo = new DirectoryInfo(path);
System.Security.AccessControl.DirectorySecurity s1 = directoryInfo.GetAccessControl();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading