The answer itself lied within the DirectoryInfo and DirectorySecurity namespaces. Using the information provided earlier from checking-for-directory-and-file-write-permissions-in-net I managed to create a recursively calling method that generates a list of the users/groups who have read/write on the folders, starting at the top and working down to the lowest directory.
string dir = "";
if (input.Text.Contains(@"\\"))
{
dir += @"\\";
}
string[] folders = input.Text.Split(new char[] { '\\', '/' }, StringSplitOptions.RemoveEmptyEntries);
foreach (string folder in folders)
{
if (dir.Contains(@"\\") && folder == folders[0])
{
dir += folder + @"\";
}
else
{
dir += folder + @"\";
ResultGroup newbox = new ResultGroup(folder);
newbox.label1.Click += (x, y) =>
{
splitContainer1.Panel2Collapsed = false;
listBox1.Items.Add(newbox.label1.Text);
};
flowLayoutPanel1.Controls.Add(newbox);
DirectoryInfo di = new DirectoryInfo(dir);
DirectorySecurity ds = di.GetAccessControl();
foreach (AccessRule rule in ds.GetAccessRules(true, true, typeof(NTAccount)))
{
newbox.listBox1.Items.Add(string.Format("{0}", rule.IdentityReference.Value));
}
}
}
This allows the user to enter a local path, e.g. "C:\Temp\Test Folder" OR a UNC Path "\Server\Share\Temp\Network Test Folder", which will then get processed folder by folder, populating the form I am using to display the data.