any way to get sharepoint groups with a given site url

Posted by standley-nguyen on Stack Overflow See other posts from Stack Overflow or by standley-nguyen
Published on 2010-05-18T10:48:24Z Indexed on 2010/05/18 10:51 UTC
Read the original article Hit count: 227

Filed under:

Hi all.

I'm getting a stuck. Suppose that I create 5 sites. For each one, I create a few sharepoint groups. So, I create a dropdownlist control to bind 5 sites and when I click on any site there, I will get sharepoint groups created on it. But I always see the dropdownlist used to bind these groups still never change. I mean it only binds a few default groups in sahrepoint everytime. The new created groups is not.

And I have confusion like this

web.AssociatedGroups web.Groups web.SiteGroups

which one we will use this case ? Please guide me

Here my snippet code

private void BindSPGroupsToDropDownList(DropDownList ddl, string siteUrl) {

        ddl.Items.Clear();
        try
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
           {
               using (SPSite site = new SPSite(siteUrl))
               {
                   using (SPWeb web = site.OpenWeb())
                   {
                       //web.SiteGroups
                       foreach (SPGroup spGroup in web.Groups)
                       {


                           ddl.Items.Add(new ListItem(spGroup.Name.Trim(), spGroup.ID.ToString()));



                       }

                   }
               }
           });
        }

}

thanks in advance

© Stack Overflow or respective owner

Related posts about sharepoint