Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Code to get sub-areas for current user

  Asked By: Nicholas    Date: Apr 24    Category: Sharepoint    Views: 1277

The below code will get me all of the sub-areas under home but it will
also get areas the current user doesn't have access to. Anyone know
how-to fix this?

'Get the topology manager
Dim topologyManager As TopologyManager = New TopologyManager
'Get the context of the web
Dim site As System.Web.HttpContext = context.Current
'Get all the porta sites
Dim sites As PortalSiteCollection = topologyManager.PortalSites
'Get the corresponding portal site context
Dim PContext As PortalContext

'home area
PContext = PortalApplication.GetContext(site)

'Get the home area's guid
Dim homeGuid As Guid = AreaManager.GetSystemAreaGuid(PContext,

'Get the Home area
Dim homeArea As Area = AreaManager.GetArea(PContext, homeGuid)

For Each childSite As Area In homeArea.Areas
If childSite.IsKeywordItem = False And childSite.Title <>
"Search" And childSite.Title <> "Targeted links on My Site" Then
newRow = ds.Tables("Sub_Menu").NewRow()
newRow("parentMenuID") = 1
newRow("subMenuTitle") = childSite.Title.ToString()
newRow("URL") = childSite.WebUrl
End If



8 Answers Found

Answer #1    Answered By: Laura Walker     Answered On: Apr 24

Isn't there something like SubwebsForCurrentUser? Can't see right now.

I can't run the code  right now (time constraint) and desk checking the
code is just making my eyes cross.

Answer #2    Answered By: Cory Brooks     Answered On: Apr 24

I sure wish there was a GetSubwebsForCurrentUser that worked for
"Areas", there is one that works for WSS sites  but I can't figure out
how-to get it to work for "Areas". At least without getting all "Areas"
user  has access  to (I think that works) but I only want the top level
Areas or sub-areas  of the "Home" Area. Let me know if you find anything
and thanks for the reply!

Answer #3    Answered By: Ruth George     Answered On: Apr 24

The following will ignore any areas  the user  doesn't have access  to:

using Microsoft.SharePoint.Portal.Security

AreaAccessChecker aac = new AreaAccessChecker(m_PortalContext,
PortalRight.ViewArea, childSite.ID);
try {
} catch(Microsoft.SharePoint.Portal.Security.AccessDeniedException) {
//do nothing - the user has no viewing rights in this area

Answer #4    Answered By: Peter Peterson     Answered On: Apr 24

I seem to be getting an error on the line below.....

Dim aac As AreaAccessChecker = New AreaAccessChecker(PContext,
PortalRight.ViewArea, childSite.ID)

Below is the error message......

C:\CustomNavigation\TopNav.vb(69): Value of type 'Integer' cannot be
converted to 'Microsoft.SharePoint.Portal.Security.PortalRight'.

Answer #5    Answered By: Kalyan Pujari     Answered On: Apr 24

GetSubwebsForCurrentUser() method is a method of SPWeb class and returns the collection of subsites to which user  is a member.

Answer #6    Answered By: Isidro Berger     Answered On: Apr 24

As I said in another post, GetSubwebForCurrentUser() does not work for
"Areas" (it get them all..........I mean all)

Answer #7    Answered By: Schuyler Le     Answered On: Apr 24

Un-real, so I finally get the AreaAccessChecker working and you need
admin right for it to run!!! So the user  get prompted when it hits that
part of the code. I can't believe there is not an easier way to get the
areas a user has access  to!!!

Answer #8    Answered By: Kristina Cox     Answered On: Apr 24

We don't get that behavior in our code. It might be hitting
System areas  and throwing up the authentication request on those areas.
I just noticed that our code  excludes those areas. We also exclude the
ones where the area  settings indicate to exclude it from the navigation.
Try embedding the code I sent you in the following if block:

if (!area.System && area.Navigation == AreaNavigation.Show) {

Didn't find what you were looking for? Find more on Code to get sub-areas for current user Or get search suggestion and latest updates.