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

Trying to find a C# script that will list me all the groups of Current Web for sake of webpart that will show users the groups and users having permission to a specific web.

I know I can get all the users by following code,

foreach (SPUser user in SPContext.Current.Web.Users)
            {
}

but then how can I actually access the Permissions List and then Access the properties of the Items.

I find this relevant webpart which is related to what I want but, its listing all the webs a user have access to, In my case I want to List all the Users/Groups have access to the Site

Cheers

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

The code below will give you the groups and the users in the groups.

foreach (SPGroup group in SPContext.Current.Web.Groups)
{
    foreach (SPUser user in group.Users)
    {

    }
}

Additionally, there is SPWeb.AllUsers wich represents all users who are members of the web or who have browsed to the site because they have access via a domain group.

SPWeb.Users only gives you the users that have been added to the web explicity (i.e. outside the comfort of a SharePoint or domain group).

share|improve this answer
    
+1 for the difference between AllUsers and Users –  SPArchaeologist Nov 20 '12 at 13:25
add comment

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.