Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

I ended up solving this one with the following proof:

static void Main(string[] args)
{
    string siteCollection = "http://marlindev/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 Type: '{1}'.", DateTime.Now.ToShortTimeString(), role.Member.GetType());

            foreach(SPRoleDefinition rd in role.RoleDefinitionBindings)
            {
                Console.WriteLine("[{0}] Role Def Type: '{1}'.", DateTime.Now.ToShortTimeString(), rd.Type);
            }

            Console.WriteLine("\n\n");
        }
    }

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.