Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5977275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:20:50+00:00 2026-05-22T21:20:50+00:00

In my Sharepoint code I display a list of all defined users via: foreach

  • 0

In my Sharepoint code I display a list of all defined users via:

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

The great part is, I can add a domain security group to a Sharepoint group (like Visitors) thus adding many users at once (simpler administration). But my code doesn’t see those users at least not until they log-in for the first time (if they have sufficient rights). In this case I can only see the domain security group SPUser object instance with its IsDomainGroup set to true.

Is it possible to get domain group members by means of Sharepoint without resorting to Active Directory querying (which is something I would rather avoid because you probably need sufficient rights to do such operations = more administration: Sharepoint rights + AD rights).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:20:51+00:00Added an answer on May 22, 2026 at 9:20 pm

    You can use the method SPUtility.GetPrincipalsInGroup (MSDN).

    All parameters are self-explaining except string input, which is the NT account name of the security group:

    bool reachedMaxCount;
    SPWeb web = SPContext.Current.Web;
    int limit = 100;
    string group = "Domain\\SecurityGroup";
    SPPrincipalInfo[] users = SPUtility.GetPrincipalsInGroup(web, group, limit, out reachedMaxCount);
    

    Please note that this method does not resolve nested security groups. Further the executing user is required to have browse user info permission (SPBasePermissions.BrowseUserInfo) on the current web.

    Update:

    private void ResolveGroup(SPWeb w, string name, List<string> users)
    {
        foreach (SPPrincipalInfo i in SPUtility.GetPrincipalsInGroup(w, name, 100, out b))
        {
            if (i.PrincipalType == SPPrincipalType.SecurityGroup)
            {
              ResolveGroup(w, i.LoginName, users);
            }
            else
            {
              users.Add(i.LoginName);
            }
        }
    }
    
    List<string> users = new List<string>();
    foreach (SPUser user in SPContext.Current.Web.AllUsers)
    {
      if (user.IsDomainGroup)
        {
          ResolveGroup(SPContext.Current.Web, user.LoginName, users);
        }
        else
        {
          users.Add(user.LoginName);
        }
    }
    

    Edit:

    […] resorting to Active Directory querying (which is something I would rather avoid because you probably need sufficient rights to do such operations […]

    That’s true, of course, but SharePoint has to lookup the AD as well. That’s why a application pool service account is required to have read access to the AD.
    In other words, you should be safe executing queries against the AD if you run your code reverted to the process account.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My Sharepoint 2007 web part executes code to start a K2 workflow process. The
Has anybody ever successfully written code to extract data from a SharePoint 2007 list
we've created a custom webpart to display announcements from all lists a user has
I'm attempting to pull a list from SharePoint via CAML and I want the
I am using SP Designer 2007 to display the custom list form. Users will
How do you debug your SharePoint 2007 code? Since SharePoint runs on a remote
I am currently publishing code behind .aspx in SharePoint. I can automatically publish the
I have to call some code in a SharePoint site that runs under the
I have some code that creates a new site in SharePoint. Upon browsing to
I have this webdav code thats creating folders in SharePoint: HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create(folderAddress);

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.