public static bool IsFileAuthorizedAccess(string path) { //TODO bool retValue; try { retValue = !string.IsNullOrWhiteSpace(path) && File.Exists(path); DirectorySecurity obj = Directory.GetAccessControl(path); FileSecurity oqbj = File.GetAccessControl(path); } catch (UnauthorizedAccessException ex) { retValue = true; } catch (Exception ex) { throw ex; } return retValue; } public static bool CanReadFile(string path) { //TODO var readAllow = false; var readDeny = false; try { var accessControlList = Directory.GetAccessControl(path); if (accessControlList == null) return false; var accessRules = accessControlList.GetAccessRules(true, true, typeof(System.Security.Principal.SecurityIdentifier)); if (accessRules == null) return false; foreach (FileSystemAccessRule rule in accessRules) { if ((FileSystemRights.Read & rule.FileSystemRights) != FileSystemRights.Read) continue; if (rule.AccessControlType == AccessControlType.Allow) readAllow = true; else if (rule.AccessControlType == AccessControlType.Deny) readDeny = true; } } catch (Exception ex) { throw; } return readAllow && !readDeny; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)