In SharePoint 2007 when you go to a site and view advanced permissions (Site Actions - Site Settings - Modify All Site Settings - Advanced Permissions) you are presented with a page that has a table of all the users and groups that can access that site as well as their permission level.
I would like to replicate that as a console output (ultimately my goal is to sync this to a database regularly for audit purposes, but for the sake of a proof, the console).
Unfortunately I don't know enough about SharePoint programming, and this is where I've got to:
static void Main(string[] args)
{
string siteCollection = "http://dev/re/ad/wf";
string version = Assembly.GetAssembly(typeof(Program)).GetName().Version.ToString();
Console.WriteLine("[{0}] SharePoint Permissions started with version '{1}'.", DateTime.Now.ToShortTimeString(), version);
using (SPWeb oWebsite = new SPSite(siteCollection).OpenWeb())
{
foreach(SPRoleAssignment role in oWebsite.RoleAssignments)
{
Console.WriteLine("[{0}] Member ID: '{1}'.", DateTime.Now.ToShortTimeString(), role.Member.ID);
Console.WriteLine("[{0}] Member Name: '{1}'.", DateTime.Now.ToShortTimeString(), role.Member.Name);
Console.WriteLine("[{0}] Member Parent: '{1}'.", DateTime.Now.ToShortTimeString(), role.Parent);
foreach(SPRoleDefinition rd in role.RoleDefinitionBindings)
{
Console.WriteLine("[{0}] Role Def Base Permissions: '{1}'.", DateTime.Now.ToShortTimeString(), rd.BasePermissions);
Console.WriteLine("[{0}] Role Def Type: '{1}'.", DateTime.Now.ToShortTimeString(), rd.Type);
Console.WriteLine("[{0}] Role Description: '{1}'.", DateTime.Now.ToShortTimeString(), rd.Description);
}
Console.WriteLine("\n\n");
}
}
}
How should I be approaching this? I'm concerned that the code above will be limited in just showing groups, I'd also like to show users that have direct access to a location, and ultimately, their permission level as well. How can I go about this?