zoukankan      html  css  js  c++  java
  • 自动生成所有导航

            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);
            }
    作者:KKcat
        
    个人博客:http://jinzhao.me/
        
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    python 中文乱码问题
    PHP读取CSV文件把数据插入到数据库,本地没有问题,阿里云测试服务器不行
    UTF-8 Unicode ANSI网页编码的区别
    php 读取csv 乱码
    zend studio(Eclipse)和PyDev搭建Python开发环境
    php 如何解决“您访问的域名有误或网页不存在”
    mysql数据去除重复及相关优化(转)
    Git的简单使用教程
    PHP mysql基础操作
    PHP两个文件的相对路径
  • 原文地址:https://www.cnblogs.com/jinzhao/p/1454828.html
Copyright © 2011-2022 走看看