Click here to Skip to main content
15,880,543 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on an application that allows users to browse particular file directories on production servers and I would like to allow the user to be able to add additional menu items whilst using the site, as well as creating a new menu item they should also be able to specify a new file directory value linked to this new menu item.

Is there a way that I can allow the end user to dynamically add additional items to this menu and set the config value without having a separate admin functionality page to create the new menu item?

Here's how the menu is setup:
<table width="100%">
                <td colspan="3" rowspan="1" style="width: 100%; height: 30px" valign="top">
                    <asp:Menu ID="Menu1" runat="server" BackColor="#B5C7DE" DynamicHorizontalOffset="2"
                        Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" OnMenuItemClick="Menu1_MenuItemClick"
                        StaticSubMenuIndent="10px" EnableViewState="False" Orientation="Horizontal" Width="100%">
                        <StaticMenuItemStyle BackColor="LightSteelBlue" HorizontalPadding="2px"
                            VerticalPadding="2px" Width="120px" Font-Bold="True" ItemSpacing="1px" />
                        <DynamicHoverStyle BackColor="#284E98" ForeColor="White" />
                        <DynamicMenuStyle BackColor="#B5C7DE" />
                        <StaticSelectedStyle BackColor="#507CD1" ForeColor="White" />
                        <DynamicSelectedStyle BackColor="#507CD1" />
                        <DynamicMenuItemStyle HorizontalPadding="5px" VerticalPadding="2px" />
                            <asp:MenuItem Text="Home" Value="Home"></asp:MenuItem>
                            <asp:MenuItem Selectable="False" Text="View Server Items" Value="View Server Items">
                                <asp:MenuItem Text="Browse Inetpub" Value="Inetpub"></asp:MenuItem>
                                <asp:MenuItem Text="Browse SrvApps" Value="SrvApps"></asp:MenuItem>
                                <asp:MenuItem Text="Browse .Net 2.0 64-bit Config" Value="Net20Config64"></asp:MenuItem>
                                <asp:MenuItem Text="Browse .Net 2.0 Config" Value="Net20Config"></asp:MenuItem>
                                <asp:MenuItem Text="View GAC" Value="GAC"></asp:MenuItem>
                                <asp:MenuItem Text="View MSMQ" Value="MSMQ"></asp:MenuItem>
                                <asp:MenuItem Text="Server Time" Value="ServerTime"></asp:MenuItem>
                                <asp:MenuItem Text="Browse Allstate Scripts" Value="AllstateTWSScripts"></asp:MenuItem>
                            <asp:MenuItem Text="Manage Sites" Value="Manage Sites" Selectable="False">
                                <asp:MenuItem Text="Control Sites" Value="Control Sites"></asp:MenuItem>
                                <asp:MenuItem Text="Control App Pools" Value="Control App Pools"></asp:MenuItem>
                                <asp:MenuItem Text="Download Logs" Value="Download Logs"></asp:MenuItem>
                            <asp:MenuItem Text="Manage Services" Value="Manage Services"></asp:MenuItem>
                            <asp:MenuItem Selectable="False" Text="Diagnostics" Value="Diagnostics">
                                <asp:MenuItem Text="View EventLog" Value="View EventLog"></asp:MenuItem>
                        <StaticHoverStyle BackColor="#284E98" BorderStyle="None" ForeColor="White" Font-Bold="False" />
                        <StaticMenuStyle BackColor="LightSteelBlue" />
        <asp:Label ID="lblPath" runat="server" Text="Home" ForeColor="Gray"></asp:Label><span style="color: gray"></span></td>
                <td rowspan="3" style="width: 100%; height: 412px" valign="top" colspan="3">
                    <asp:MultiView ID="MultiView1" runat="server">
                        <asp:View ID="View1" runat="server">
                            <uc3:ucHomeView ID="UcHomeView1"  runat="server" />
                        <asp:View ID="View2" runat="server">
                             <uc8:ucBrowseFiles id="UcBrowseFiles1"  runat="server"></uc8:ucBrowseFiles>
                        <asp:View ID="View3" runat="server">
                            <uc4:ucSites id="UcSites1"  runat="server">
                        <asp:View ID="View4" runat="server">
                            <uc5:ucServices id="UcServices1"  runat="server">
                        <asp:View ID="View5" runat="server">
                            <uc6:ucEventLogView id="UcEventLogView1"  runat="server">
                        <asp:View ID="View6" runat="server">
                            <uc8:ucGacBrowser id="UcGACBrowser1"  runat="server">
                        <asp:View ID="View7" runat="server">
                             <uc9:ucAppPools id="UcAppPools1"  runat="server"></uc9:ucAppPools>
                        <asp:View ID="View8" runat="server">
                            <uc10:ucDownloadFile ID="UcDownloadFile1"  runat="server" />
                        <asp:View ID="View9" runat="server">
                            <uc11:ucMSMQBrowser ID="UcMSMQBrowser1"  runat="server" />
                        <asp:View ID="View11" runat="server">
                            <uc12:ucServerTime ID="UcServerTime"  runat="server" />
                    </asp:MultiView> </td>

Web.config Values:
<!--<add key="Inetpub" value="d:\inetpub"/>-->
<add key="Inetpub" value="c:\inetpub"/>
<add key="Srvapps" value="d:\srvapps"/>
<add key="GAC" value="C:\WINDOWS\assembly\GAC"/>
<add key="Net20Config64" value="C:\WINDOWS\Microsoft.NET\Framework64\v2.0.50727\CONFIG"/>
<add key="Net20Config" value="C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG"/>
<add key="AllstateTWSScripts" value="d:\allstate\"/>
<!--<add key="IISLogDir" value="d:\inetpub\LogFiles"/>-->
<add key="IISLogDir" value="c:\inetpub\LogFiles"/>
<!--<add key="IISLogDir2008" value="d:\inetpub\Logs"/>-->
<add key="IISLogDir2008" value="c:\inetpub\Logs"/>
<add key="ViewExt" value=".txt;.log;.config;.ini;.bat;.html"/>
<add key="CleansePasswords" value="false"/>
<!--timeout in seconds-->
<add key="ServiceTimeout" value="30"/>
<add key="ResourceTimeout" value="300"/>
<!--Limit Event Log entries-->
<add key="MaxEvents" value="1000"/>
<add key="MaxRemoteEvents" value="200"/>
ZurdoDev 21-Mar-13 7:51am    
Although I have never tried see if the menu.Items collection has an Add() method. Or, you can see how it is rendered in html and then use jquery to add items.

Your menu is defined in the code. You probably don't want to allow user to alter code. So change your point of view: you don't need to allow user to add menu items, you need to define and put in place a feature that can populate the menu fully or partially in a dynamic manner. You also need to store and retrieve the data of these dynamic items somewhere: in a database for example. Please look at following article for a possible solution: Dynamically populating menu items from the database in ASP.NET[^]
Share this answer
pmcm 21-Mar-13 10:01am    
this is an option I have been looking at only using sitemap.xml instead of a DB
protected void Page_Load(object sender, EventArgs e)
    if (User.IsInRole("admin"))
        mnu.Items.Add(new MenuItem
            Text = "Administer web site",
            NavigateUrl = "~/admin.aspx"
Share this answer
pmcm 21-Mar-13 9:59am    
whilst your solution would work for dynamically add items to the Menu it does not allow the user to specify the Text & Value. I know allowing the user to specify these values is a security risk so I will have to investigate this requirement further.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900