I'm scanning the folder for files and I need to get each file's permissions for current user in any way to be represented as a string. So for the attached file's properties I would like to represent something like f-m-r-w string.
I'm trying to accomplish this in my scan loop like this, but getting empty strings. Could you hint to where should I go from here or chose another approach? Thanks in advance!
string permissionShort = string.Empty;
DirectorySecurity dSecurity = Directory.GetAccessControl(_directory.FullName);
foreach (FileSystemAccessRule rule in dSecurity.GetAccessRules(true, true, typeof(NTAccount)))
{
if (rule.FileSystemRights == FileSystemRights.Write)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.Read)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.AppendData)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.Modify)
permissionShort = permissionShort + "x";
if (rule.FileSystemRights == FileSystemRights.ExecuteFile)
permissionShort = permissionShort + "x";
}
FileSystemRights is a flagged enum, that means you must perform an AND operation to test for a single value of the enum.