Welcome to MSDN Blogs Sign in | Join | Help

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;

 

Published Wednesday, April 14, 2004 1:11 PM by danielmcpherson
Filed under:

Comments

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

Thursday, April 15, 2004 12:23 AM by Paul
Can't it BE one line?

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

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

Thursday, April 15, 2004 12:55 AM by Paul
oops, one more semicolon there than there oughta be

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

Thursday, April 15, 2004 10:39 AM by Daniel McPherson
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>
New Comments to this post are disabled
 
Page view tracker