Creating a DotNetNuke menu out of an Asp.Net menu

So I tend to use Dotnetnuke alot for my side projects and its just generaly a good portal. But the default solpartmenu was always a creative challange making it look good. And the Asp.net menu provider seems to have a lot of code in it. So i looked around and saw some free menus, but they where always quirky… and when i used reflector on them i could see why. 

Which led to this posting. As you can see my code is always very simple, i hate re inventing the wheel. What this control is doing is populating the menuitemcollection.

[code lang=”csharp”]
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
namespace QuickMax.UI
{
public class DnnAspNetMenu : System.Web.UI.WebControls.Menu
{
DotNetNuke.Entities.Modules.PortalModuleBase _DnnBase;
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
_DnnBase = new DotNetNuke.Entities.Modules.PortalModuleBase();
foreach (DotNetNuke.Entities.Tabs.TabInfo tab in _DnnBase.PortalSettings.DesktopTabs)
{
if (tab.IsVisible && tab.Level == 0)
{
bool badd = false;
foreach (DotNetNuke.Security.Permissions.TabPermissionInfo tbi in tab.TabPermissions)
if (_DnnBase.UserInfo.IsInRole(tbi.RoleName))
badd = true;
if (badd)
{
MenuItem mnuItem = new MenuItem();
mnuItem.Text = tab.TabName;
mnuItem.NavigateUrl = tab.FullUrl;

mnuItem.Selected = tab.TabID.Equals(_DnnBase.PortalSettings.ActiveTab.TabID);FillChildren(ref mnuItem, tab);
this.Items.Add(mnuItem);
}
}
}
}
private void FillChildren(ref MenuItem mnuitem, DotNetNuke.Entities.Tabs.TabInfo parent)
{
foreach (DotNetNuke.Entities.Tabs.TabInfo tab in _DnnBase.PortalSettings.DesktopTabs)
{
if (parent.TabID == tab.ParentId)
{
bool badd = false;
foreach (DotNetNuke.Security.Permissions.TabPermissionInfo tbi in tab.TabPermissions)
if (_DnnBase.UserInfo.IsInRole(tbi.RoleName))
badd = true;
if (badd)
{
MenuItem mnuItem = new MenuItem();
mnuItem.Text = tab.TabName;
mnuItem.NavigateUrl = tab.FullUrl;

mnuItem.Selected = tab.TabID.Equals(_DnnBase.PortalSettings.ActiveTab.TabID);FillChildren(ref mnuItem, tab);
mnuitem.ChildItems.Add(mnuItem);
}
}
}
}
}
}
[/code]

Leave a Reply

Your email address will not be published. Required fields are marked *