Thursday, August 26, 2010

How to list all the directories and files in to a asp.net menu

<%@ Page Language="C#" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <script runat="server">
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            DirectoryInfo d = new DirectoryInfo(Server.MapPath("~/"));
            MenuItem root = new MenuItem("\\", d.FullName);
            this.AddChildren(root, d);
            this.menuNavigation.Items.Add(root);
        }
        private void AddChildren(MenuItem item, DirectoryInfo direcotry)
        {
            foreach (DirectoryInfo child in direcotry.GetDirectories())
            {
                MenuItem childItem = new MenuItem(child.Name, child.FullName);
                item.ChildItems.Add(childItem);
                if (child.GetDirectories().Count() > 0)
                    this.AddChildren(childItem, child);
            }
            foreach (FileInfo child in direcotry.GetFiles())
            {
                MenuItem childNode = new MenuItem(child.Name, child.FullName);
                item.ChildItems.Add(childNode);
            }
        }       
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Menu runat="server" ID="menuNavigation" />
    </form>
</body>
</html>

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...