SPWeb.GetSubwebsForCurrentUser Method
Returns the collection of subsites beneath the current Web site of which the current user is a member.
| Name | Description |
|---|---|
| SPWeb.GetSubwebsForCurrentUser () |
Returns the collection of subsites beneath the current site of which the current user is a member.
|
| SPWeb.GetSubwebsForCurrentUser (Int32) |
Returns the collection of subsites beneath the current Web site of which the current user is a member based on the specified site definition.
|
| SPWeb.GetSubwebsForCurrentUser (Int32, Int16) |
Returns the collection of subsites beneath the current Web site in which the current user is a member, based on the specified site definition and configuration.
|
Possible Workaround
As stated previously this does not work if a site has a child site with no permissions, but a site under that child site where the user does have permissions, it won't get the grandchild site.
Try using
SPSecurity.RunWithElevatedPrivileges
(http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsecurity.runwithelevatedprivileges.aspx)
and looping through the webs collection of the SPWeb object. Then run the DoesUserHavePermissions with the current user context to see what sites the user has rights too.
- 4/16/2010
- Andersen Jason Minnesota
Works only for Site Collection
This only works if the current SPWeb object is the RootWeb of the Site Collection.
Don;t expect any result when the current site is only a simple web.
Don;t expect any result when the current site is only a simple web.
- 11/26/2007
- Ankit Jain
- 4/2/2009
- marlobello
Problem with Site Level Visibility with Custom Permissions
Note that this will work only at the top or specified level if the user doesn't have permissions via inheritance in sharepoint.
If a user doesn't have permission at a top level site (parent) although they have permission in a subsite (child), the child will not get returned by this method.
Since the user doesn't have permission at the top level, it is hidden from the current user's context and therefore doesn't get queried by this method.
- 11/30/2007
- Derek Himes
- 11/30/2007
- Derek Himes