0

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?

0

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;
            this.Controls.Add(n);
            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

http://msdn.microsoft.com/en-gb/library/microsoft.sharepoint.spweb.sitegroups.aspx

0

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){
                          //keep
              }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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