SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I go to 'people and groups' then select a group I am looking at a list view with a few columns. Is there a way to retreive this view programmatically?

share|improve this question

The following code example uses the SiteGroups property to return the collection of groups in the current site collection, and also displays the name of each group.

This example requires using directives for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

using (SPSite siteCollection = new SPSite(SPContext.Current.Web.Url))
    using (SPWeb web = siteCollection.OpenWeb())

        int IDLable = 0;
        SPGroupCollection collGroups = Web.SiteGroups;
        foreach (SPGroup oGroup in collGroups)
            //list the groups
            //the code below returns each group, do what you want with it
            Label n = new Label();

            n.Text = oGroup.Name;
            n.Id = IDLable;

iv ammended the above code for a custome webpart or what ever you want ;) it will produce a lable with the text of the group for each one with a unique ID for each lable

share|improve this answer
up vote 0 down vote accepted

There is a sinlge list that controls the views for all SPGroups, this list is known as the 'SiteUserInfoList'. To get a proper collection of my data I used th following..

 SPUserCollection members = web.SiteGroups["name"].users;
 string str = "<Where><In><FieldRef Name='myAccount'/><Values>";
 foreach( SPUser u in members){  str+= "<Value Type='"+u.login+"'/>";

 SPQuery q = New SPQuery();
 q.Query= str+"</Values></In></Where>";
 SPList list = web.Lists["SiteUserInfoList"];
 SPListItemCollection data = list.GetItems(q);

To get the fields I was looking for

   foreach(string internalName in  list.defaultView.viewfields){
              if( ! list.Fields[internalName].hidden){
share|improve this answer

Your Answer


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.