Restrict acces to a folder(and all its files and subdirectories) stored on a sd card C#

155 Views Asked by At

Hy, is there any posibillities to restrict acces to a folder stored on an sd card? I tried this but it doesn't work...Any ideas are welcome. Thanks...

public static void setRight(string dirName,string account, FileSystemRights rights, AccessControlType controlType)
    {
        DirectoryInfo dir = new DirectoryInfo(dirName);

        DirectorySecurity dSecurity = new DirectorySecurity();// Directory.GetAccessControl(dirName);

        // Add the FileSystemAccessRule to the security settings.
        dSecurity.AddAccessRule(new FileSystemAccessRule(account, rights, controlType));

        // Set the new access settings.
        dir.SetAccessControl(dSecurity);
        Directory.SetAccessControl(dirName, dSecurity);

    }
1

There are 1 best solutions below

0
On

Try using the File.Encrypt and File.Decrypt methods. You can use recursion to encrypt directories, by encrypting all files in them.