Whats the quickest way to get a reference to the current Portal Area via a Web Part?


Useful little code snippet that answers a common question. 

This is the most efficient way I know of to retrieve a reference to the Portal Area a web part is instantiated on.

Let me know if you have a better way! (Wouldn’t it be nice if it were just a single line?)


SPWeb ThisWeb = SPControl.GetContextWeb(Context);

PortalContext ThisPortalContext = PortalApplication.GetContext(Context);

Area thisArea = AreaManager.GetArea(ThisPortalContext, ThisWeb.ID);

AreaTitle = thisArea.Title;

 

Comments (3)

  1. Paul says:

    Can’t it BE one line?

    AreaTitle = AreaManager.GetArea(PortalApplication.GetContext(Context);, SPControl.GetContextWeb(Context).ID).Title;

  2. Paul says:

    oops, one more semicolon there than there oughta be

  3. Daniel McPherson says:

    Yes, it could be one line, a little harder to read, but it is on one line. I really meant it would be great if you could do this with just one call. <grin>

Skip to main content