Hi
In the .NET Framework have a features to retrieve file permission list using "Access control List "
using System.Security.AccessControl;
using System.Security.Principal;
private string GetAccessControlInformation(string filename)
{
StringBuilder info = new StringBuilder();
info.AppendLine("ACE entries for the file \"" + filename + "\":");
info.AppendLine();
FileSecurity security = File.GetAccessControl(filename);
AuthorizationRuleCollection acl = security.GetAccessRules(true, true,
typeof(System.Security.Principal.NTAccount));
foreach (FileSystemAccessRule ace in acl)
{
string aceInfo = GetAceInformation(ace);
info.AppendLine(aceInfo);
}
return info.ToString();
}
private string GetAceInformation(FileSystemAccessRule ace)
{
StringBuilder info = new StringBuilder();
string line = string.Format("Account: {0}", ace.IdentityReference.Value);
info.AppendLine(line);
line = string.Format("Type: {0}", ace.AccessControlType);
info.AppendLine(line);
line = string.Format("Rights: {0}", ace.FileSystemRights);
info.AppendLine(line);
line = string.Format("Inherited ACE: {0}", ace.IsInherited);
info.AppendLine(line);
return info.ToString();
}
VB.NET
Private Function GetAccessControlInformation(ByVal filename As String) As String
Dim info As New StringBuilder()
info.AppendLine("ACE entries for the file """ & filename & """:")
info.AppendLine()
Dim security As FileSecurity = File.GetAccessControl(filename)
Dim acl As AuthorizationRuleCollection = security.GetAccessRules(True, True, GetType(System.Security.Principal.NTAccount))
For Each ace As FileSystemAccessRule In acl
Dim aceInfo As String = GetAceInformation(ace)
info.AppendLine(aceInfo)
Next
Return info.ToString()
End Function
Private Function GetAceInformation(ByVal ace As FileSystemAccessRule) As String
Dim info As New StringBuilder()
Dim line As String = String.Format("Account: {0}", ace.IdentityReference.Value)
info.AppendLine(line)
line = String.Format("Type: {0}", ace.AccessControlType)
info.AppendLine(line)
line = String.Format("Rights: {0}", ace.FileSystemRights)
info.AppendLine(line)
line = String.Format("Inherited ACE: {0}", ace.IsInherited)
info.AppendLine(line)
Return info.ToString()
End Function
Use:
Call this function GetAccessControlInformation(yourfolderPath), then it's return the all information.
Thanks
Karthik
www.f5Debug.net
Sharadgupta2110, if this helps please login to Mark As Answer. | Alert Moderator