SharePoint Events

  5/13/2013 - Conference: SharePoint Summit 2013
  5/21/2013 - Webcast: SharePoint 2013 and ECM: Content Migration and Storage
  5/22/2013 - Webcast: Managing CAD in SharePoint
  5/23/2013 - Webcast: SharePoint Document Automation and E-Forms for Financial Services
  5/24/2013 - Webcast: What's New in Search for SharePoint 2013

 SharePoint Videos

  Why SharePoint 2013
  SharePoint 2013 Launch
  SharePoint 2013 Migration and Governance
  SharePoint 2013 and Enterprise Content Management
  Top Benefits of SharePoint 2013
  What's New in Business Intelligence in Office and SharePoint 2013
  SharePoint and Office 2013 Integration
  SharePoint 2013 Infrastructure Preview
  SharePoint, Lync, and, Exchange in the Cloud with Office 365
  Advanced Reporting in SharePoint with Microsoft Power View

 Archives

Opening SharePoint Links in a new windowUse SHIFT+ENTER to open the menu (new window).
Mail Enabled Lists vs. The Missing Windows 2008 POP3/IMAP Server Use SHIFT+ENTER to open the menu (new window).
7 Tools for SharePoint DevelopersUse SHIFT+ENTER to open the menu (new window).
Public Facing Masterpage TechniquesUse SHIFT+ENTER to open the menu (new window).
How to Quickly Deploy and Activate a Timer Service to Your Site CollectionUse SHIFT+ENTER to open the menu (new window).
Custom SharePoint Master Page Feature with WSP BuilderUse SHIFT+ENTER to open the menu (new window).
Date Math with InfoPathUse SHIFT+ENTER to open the menu (new window).
Enterprise Search Tricks and Tips Part 1Use SHIFT+ENTER to open the menu (new window).
Populating Word Documents With SharePoint Data. Try The DIP!Use SHIFT+ENTER to open the menu (new window).
Programmatic Deep Dive into Blank SharePoint Lookup ColumnsUse SHIFT+ENTER to open the menu (new window).
1 - 10 Next
Web.Groups vs. Web.SiteGroups

By: Arjun Chakraborty

Introduction:

Often times, I have to remind myself, is it appropriate to use web.SiteGroups, or web.Groups?  The same can be asked about web.SiteUsers vs. web.Users, but the convention is pretty similar.  Ultimately, I found out the difference:  Web.SiteGroups contains all the groups within the whole site collection (SPSite), regardless of the site (SPWeb) itself.  It almost makes more sense as a property of SPSite.  Web.Groups, on the other hand, only contains the groups which have some level of permission in that specific site (SPWeb).  Web.Groups can clearly be different from one subsite to another, unless role inheritance is always observed.

We should note, groups are a ‘property’ of the site collection, not the specific sites.  It’s not that way in code, but any group created anywhere is always available throughout the site collection.  So, a group created from the subsite’s site settings page will be available (for people pickers, and role assignments) within the super site.

To Demonstrate the difference, I created a site collection (called Root), and a subsite underneath it (called Sub Site).  When creating the subsite, I noted to not inherit permissions, and to create 3 new groups for the subsite.  In each site, I ran a workflow that would iterate through web.Groups and web.SiteGroups.  Before each iteration, the list’s size is noted.  Afterwards, In each iteration, the group names are also noted.

Result:

Here are all the groups within the site collection:

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

These groups were automatically generated by SharePoint.  When creating the subsite, if permissions were inherited, the 3 sub site groups would not have been created.

Here are the permissions for Root…

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

…and for Sub Site…

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

Once the workflows were run on the two sites, here were the results:

Root:
(Remember, Root site was set to give permission to all 6 groups, while Sub Site was not.)

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

Sub Site:

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

Here is the code block within the workflow which generated these Notes:

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

(Note, not putting any output in the catch block is generally a BAD practice.  It’s called exception swallowing.  It will give the illusion that everything is alright, when something might be going awry.  Sometimes, you will do this if you really don’t care what the result of that try was, but be sure to use with caution.)

Bonus:

You might notice that I also included web.AssociatedGroups.  This one is tricky, and I don’t really see a lot of use for it.  After playing around with it, I realized, if you create a group from the set permissions page for any site (SPWeb), that group becomes associated with that site.  This remains true, EVEN if that group no longer has ANY permission on the associated site (SPWeb).  Iterating through the AssociatedGroup list really only tells you if the group was created from this site’s site settings page or not.

Here is what the workflow returned for the Sub Site site, after I added a Test Group from the Sub Site’s permissions page, and then promptly removed that group’s permission from the Sub Site:

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

Just for fun, this is what the workflow noted for the Root Site as well.  Note, the Root Site did not receive any permissions for the Test Site:

The_SharePoint_Blog_Web.Groups_vs._Web.SiteGroups

Conclusion:

In conclusion, I would say, if you need to access any group at all within your Site Collection/Solution, for whatever reason, then you better use Web.SiteGroups.  If, on the other hand, you wanted to iterate through every group that can access your particular subsite (maybe you want to add users to those particular groups), use web.Groups.  Finally, I cannot think of any good use for the AssociatedGroups list.

By: Arjun Chakraborty

        

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Your Name *


e-mail address *


Website (optional)


Comment *


Attachments

 Subscribe

  GigWerks RSS  Gig Werks Mailing List 

 Contact Us

 Connect

 Resources

  On Demand SharePoint Webcast Recordings
  Upcoming Webinars
  SharePoint Resources
  Business Intelligence Resources
  Gig Werks Website



©2009 Gig Werks. All rights reserved. Privacy Policy