public static bool HasAccessToFile()

in Configurator/Base/Classes/DirectoryServicesWrapper.cs [509:561]


    public static bool HasAccessToFile(SecurityIdentifier principalSid, string path, FileSystemRights? fileSystemRights)
    {
      if (principalSid == null)
      {
        throw new ArgumentNullException(string.Format(Resources.MissingParameterGenericError, "principal name"));
      }

      if (string.IsNullOrEmpty(path))
      {
        throw new ArgumentNullException(string.Format(Resources.MissingParameterGenericError, "file path"));
      }

      var fileInfo = new FileInfo(path);
      if (!fileInfo.Exists)
      {
        throw new Exception(string.Format(Resources.FileDoesNotExist, path));
      }

      var rules = GetAuthorizationRules(fileInfo);
      if (rules == null)
      {
        throw new Exception(string.Format(Resources.AuthorizationRulesRetrievalFailed, path));
      }

      foreach (FileSystemAccessRule rule in rules)
      {
        var ruleValue = rule.IdentityReference.Value;
        if (string.IsNullOrEmpty(ruleValue))
        {
          throw new ArgumentNullException(string.Format(Resources.MissingParameterGenericError, "rule"));
        }

        var securityIdentifier = GetSecurityIdentifier(ruleValue.Contains("\\") ? ruleValue.Split('\\')[1] : ruleValue);
        if (securityIdentifier == null
            || securityIdentifier.Value != principalSid.Value)
        {
          continue;
        }

        if (rule.AccessControlType != AccessControlType.Allow)
        {
          return false;
        }

        if (fileSystemRights != null
            && rule.FileSystemRights == fileSystemRights)
        {
          return true;
        }
      }

      return false;
    }