Ultimate Collection - { fslBlog & faisalmb.com } Ultimate Collection - { fslBlog & faisalmb.com }   
Blog   |   Site   |   Posts (347)   |   Tags Xplorer   |   Feed Subscribe Free! Aha! you surfing post Sharepoint - SPWeb.Groups... Sign in    Partner Site - Real Home Contact Search   

Thu

11

Feb

2010

Thu-11-02-2010
   

Sharepoint - SPWeb.Groups Vs SPWeb.SiteGroups



SPWeb has two sharepoint cross-site group collection, SPWeb.Groups and SPWeb.SiteGroups.

SPWeb.Groups returns collection of cross-site groups which has some permission on the site. So if you add group from a site without any permission on the site, then this group wont appear in SPWeb.Groups collection, but it will appear in SPWeb.SiteGroups collection.

You can not use SPWeb.Groups.Add method to add new cross-site group, you need to use SPWeb.SiteGroup.Add method for this purpose.

In addition to this SPWeb has a property AssociatedOwnerGroup, which will return the required SPGroup. You can iterate the SPGroup users to get the list of all owners of the site.

 foreach (SPUser user in web.AssociatedOwnerGroup.Users)
 {
      // .. list all the users                        
 }

 

Finding and adding group

SPGroup  group = GetSiteGroup(web, "groupName");
if (null == group)
{
 web.SiteGroups.Add("groupName", web.AssociatedOwnerGroup, null, "Test Group description");
}

 


private static SPGroup GetSiteGroup(SPWeb web, string name)
{
    foreach (SPGroup group in web.SiteGroups)
    {
 if (group.Name.ToLower() == name.ToLower())
 {
     return group;
 }
    }
 return null;
}

 

 


Comments

Add Comment Add comment

 
 
 
   Country flag

Click to change image  --> 

biuquote
  • Comment
  • Preview
Loading





Intro

Faisal Bashir
Consultant / Software Architect
KalSoft Limited
Microsoft Certified Technology Specialist.
Currently in Dubai. [more]

Right Now

How could u reach the pearl by only looking at the sea? if u seek the pearl, be a diver: the diver needs several qualities, he must trust his rope and his life to the Friend's hand, he must stop breating and he must jump - Jalaluddin Rumi.

Recent Comments

Comment RSS

Calendar

<<  February 2012  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
2728291234
567891011

View posts in large calendar

When you enter the toilet you should say, In the Name of Allah, I seek protection in You from unclean spirits, male and female. (Muhammad - peace be upon him - sallallaho alaihi wassallam) (ref. Abu Dawud 4/264, Ahmad 2/389 and Fath Al-Bari 1/254)
383210 hits. (Best viewed @ 1024x768 resolution min.) Comments here...
© 2001-2011 Muhammad Faisal | Disclaimer | Contact | Partner Site