private void RecurseDirectories(string path) { try { List <string> directories = Directory.GetDirectories(path).ToList(); foreach (string directory in directories) { _folders.Insert(0, directory); UpdateFoldersIdentifiedCount(); UpdateFolersLeftToProcessCount(); RecurseDirectories(directory); } } catch (UnauthorizedAccessException exc) { if (_getFileDetails) { FileDetails details = new FileDetails(); details.Error = "Exception - Folder Access Exception"; details.Path = path; SaveFileDetailsToFile(details); } else if (_getFolderSecurityDetails) { FolderSecurityDetails details = new FolderSecurityDetails(); details.Error = "Exception - Folder Access Exception"; details.Path = path; SaveFolderSecurityDetailsToFile(details); } } }
private void SaveFolderSecurityDetailsToFile(FolderSecurityDetails details) { using (StreamWriter writer = File.AppendText(_outputFileName)) { writer.WriteLine(details.ToCsvFormattedString()); } }
private void GetFolderSecurityDetails(string path) { DirectorySecurity dirSec = null; try { dirSec = Directory.GetAccessControl(path); } catch (UnauthorizedAccessException exc) { FolderSecurityDetails details = new FolderSecurityDetails() { Path = path, Error = "Unauthroized Access Exception" }; SaveFolderSecurityDetailsToFile(details); return; } AuthorizationRuleCollection authColl = dirSec.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount)); foreach (AuthorizationRule authRule in authColl) { AccessRule accessRule = authRule as AccessRule; FolderSecurityDetails details = new FolderSecurityDetails() { Path = path, IdentityReference = accessRule.IdentityReference.Value, InheritanceFlags = accessRule.InheritanceFlags.ToString(), IsInherited = accessRule.IsInherited, PropagationFlags = accessRule.PropagationFlags.ToString(), AccessControlType = accessRule.AccessControlType.ToString() }; SaveFolderSecurityDetailsToFile(details); } }
private void RecurseDirectories(string path) { try { List<string> directories = Directory.GetDirectories(path).ToList(); foreach (string directory in directories) { _folders.Insert(0, directory); UpdateFoldersIdentifiedCount(); UpdateFolersLeftToProcessCount(); RecurseDirectories(directory); } } catch (UnauthorizedAccessException exc) { if (_getFileDetails) { FileDetails details = new FileDetails(); details.Error = "Exception - Folder Access Exception"; details.Path = path; SaveFileDetailsToFile(details); } else if (_getFolderSecurityDetails) { FolderSecurityDetails details = new FolderSecurityDetails(); details.Error = "Exception - Folder Access Exception"; details.Path = path; SaveFolderSecurityDetailsToFile(details); } } }