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:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...