Logo 
Search:

MOSS Forum

Ask Question   UnAnswered
Home » Forum » MOSS       RSS Feeds

How to get the main menu content from MOSS

  Asked By: Hemali    Date: Aug 26    Category: MOSS    Views: 1360

I have been reviewing how to retrieve the content from MOSS through
C# from the "tabbed main menu" that appears on a collaboration
portal. I came up with the below function that does retrieve most of
the content, however, when I compile (and it does compile and run)
that TopologyManager is obsolete and AreaManager is obsolete.

public string[] GetMenuContent(string PortalURL)
{
ArrayList alAreas = new ArrayList();

TopologyManager tm = new TopologyManager();
PortalSite site = tm.PortalSites[new Uri(PortalURL)];
PortalContext portalContext = PortalApplication.GetContext
(site);
Guid objCurrentAreaGuid;

// Get the current area GUID from the webpart - some of
the MOSS 07 portal types
// don't have these areas
objCurrentAreaGuid = AreaManager.GetSystemAreaGuid
(portalContext, SystemArea.News);

//Get an area object of the current area
Area objArea = AreaManager.GetArea(portalContext,
objCurrentAreaGuid);

//Get the parent area GUID and make that an area object
Guid objParentAreaGuid = objArea.ParentID;
Area objParentArea = AreaManager.GetArea(portalContext,
objParentAreaGuid);

//Gets the sub-areas of the parent into a collection and
writes out each name
foreach (Area objSiblingArea in objParentArea.Areas)
{
alAreas.Add(objSiblingArea);
}

//Convert ArrayList to string[]
int i = 0;
string[] arReturnValue = new string[alAreas.Count];
foreach (Area area in alAreas)
{
arReturnValue[i++] = area.Title;
}

return arReturnValue;
}

I guess what I am asking is "how can this be rewritten with current
classes?". Also can someone point me in the right direction to pull
the content - the SPWeb objects from the site directory? And once I
have the SPWeb object, how do I know if the User has selected this
site to be a tab on the main menu?

Share: 

 

6 Answers Found

 
Answer #1    Answered By: Nathaniel Davis     Answered On: Aug 26

TopologyManager and AreaManager are holdovers from SPS 2003 and should
no longer be used. There is now an easier way. The Tabbed TopNavbar is
actually an ASPMENU control that is bound to a SiteMapDataSource that is
in turn bound to a SiteMapProvider. Try the following code instead.

private PortalSiteMapNode currentNode;

private PortalSiteMapNode rootNode;

private PortalSiteMapProvider currentSiteMap;

// The CombinedNavSiteMapProvider is what the TopNavbar is normally
bound to

currentSiteMap = PortalSiteMapProvider.CombinedNavSiteMapProvider;

//Retrieve the root Node of the selected  Nav (Top Level site  unless
inheritance is broken)

rootNode = (PortalSiteMapNode)currentSiteMap.RootNode;

//Retrieve the currently selected Node

currentNode = (PortalSiteMapNode)currentSiteMap.CurrentNode;

PortalSiteMapNodes then have the following properties that you can use
depending on what you want.

ParentNode - parent  if any

PreviousSibling and NextSibling - two peer siblings next to current  Node
in hierarchy

childNodes - a collection  of Child nodes below the current Node

Nodes have two important properties - Url and Title which are the
Address and the name of the Node.

 
Answer #2    Answered By: Zoe Cotton     Answered On: Aug 26

I tried this function, however, the call to
PortalSiteMapProvider.CombinedNavSiteMapProvider returns NULL. I am using
this function  in a web service. Should I be passing something into the
function?

 
Answer #3    Answered By: Alexander Scott     Answered On: Aug 26

Sorry, I didn't know it was a web service. This will only work when
there is a page present. The SiteMapProviders are instantiated and
loaded based on the context of the page.

About the only way to do it in a web service would be manually.

1) Instantiate an SPSite object  using the URL of a site  in the site
collection

2) Instantiate an SPWeb object using the openweb or rootweb method
of the site collection  object

3) Recursively walk the hierarchy of the site collection using the
webs collection of each SPWeb object.

That won't give you exactly the same as the Top Nav bar, but it would
give you the hierarchy.

Where are you running the program that you are doing this in a
Webservice rather than straight code? If you aren't on a SharePoint
page I don't think there is an easy way to retrieve  the navigation
contents.

 
Answer #4    Answered By: Benito Carey     Answered On: Aug 26

I am running this code as a web service. This web service is called from
within a Silverlight application/Page.xmal that I currently have implemented
within a MOSS webpart. I want to remove the MOSS tabbed menu  from a
custom.master page and replace it with the Silverlight application. I have
been able to add a Silverlight Photoviewer to the custom.master page with
success. I also have the Silverlight Photoviewer built and running as a
webpart - it pulls the *.jpg urls from a picture library.

I have created my custom.master from the default.master. Would you know how
I can remove the tabbed menu from the master page?

 
Answer #5    Answered By: Ebony Perkins     Answered On: Aug 26

Removing the Tabbed menu  from the master page is easy. Search on the
masterpage for the two AspMenu controls. One is the TopNavbar and the
other the QuickLaunch menu. You should be able to tell which is which
from the ID of the control. I don't think it is a required control on
the page, so you could probably just remove it, or change the CSS to set
display:none.

I see what you are trying to do, but I'm not sure if its possible
without a LOT of code. As I said the top nav is an AspMenu that is
bound to a SiteMapDataSource on the page that is in turn bound to a
PortalSiteMapProvider defined in the web.config. It's bound at runtime,
so I'm not sure how you would get at it via a webservice. You might try
instantiating a new SiteMapDataSource in the webservice and binding that
to the PortalSiteMapProvider in the web.config.

 
Answer #6    Answered By: Anu K     Answered On: Aug 26

What is purpose of your web service? What are you trying to accomplish?

 
Didn't find what you were looking for? Find more on How to get the main menu content from MOSS Or get search suggestion and latest updates.




Tagged: