This topic has not yet been rated - Rate this topic

SPWeb.GetSubwebsForCurrentUser Method

Windows SharePoint Services 3
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.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
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. 


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.
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.