Loading

自动生成所有导航

        protected void Page_Load(object sender, EventArgs e)
        {
            string htmlSiteBar = string.Empty;
            string ulFormat = "<ul>{0}</ul>";
            string liFormat = "<li>{0}</li>";
            string aFormat = "<a href='{0}'>{1}</a>";

            foreach (string file in Directory.GetFiles(Server.MapPath("~"), "*.aspx", SearchOption.AllDirectories))
            {
                string url = Page.ResolveClientUrl("~/" + SubRoot(file).Replace("\\", "/"));
                htmlSiteBar += (string.Format(liFormat, string.Format(aFormat, url, SubRoot(file).Replace(".aspx", string.Empty).Replace("\\", "/"))));
            }
            htmlSiteBar = string.Format(ulFormat, htmlSiteBar);
            txtPages.Text = htmlSiteBar;
        }
        string SubRoot(string fullPath)
        {
            return fullPath.Replace(Server.MapPath("~"), string.Empty);
        }
posted @ 2009-05-12 14:25  today4king  阅读(345)  评论(0编辑  收藏  举报