• 程序生成SiteMapPath文件


     1 //创建站点地图
     2         private void CreateSiteMap(DataSet ds)
     3         {
     4 
     5             XmlDeclaration declareation;
     6             declareation = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);
     7             xmlDoc.AppendChild(declareation);
     8 
     9             XmlElement xeRoot = xmlDoc.CreateElement("siteMap");
    10             xmlDoc.AppendChild(xeRoot);
    11 
    12             XmlElement xroot = xmlDoc.CreateElement("siteMapNode");
    13             xroot.SetAttribute("title", "");
    14             xroot.SetAttribute("url", "#");
    15             xeRoot.AppendChild(xroot);
    16 
    17             for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
    18             {
    19                 DataRowView row = ds.Tables[0].DefaultView[i];
    20 
    21                 string MainMenu = row["MainMenu"].ToString();
    22                 string NavigateUrl = row["NavigateUrl"].ToString();
    23                 if (MainMenu != str)
    24                 {
    25                     XmlElement siteMapNode = xmlDoc.CreateElement("siteMapNode");
    26                     siteMapNode.SetAttribute("title", MainMenu);
    27                     siteMapNode.SetAttribute("description", "");
    28                     siteMapNode.SetAttribute("url", NavigateUrl);
    29                     xroot.AppendChild(siteMapNode);
    30                     str = AddChildNode(MainMenu);
    31                 }
    32             }
    33             xmlDoc.Save(Server.MapPath("\Web.sitemap"));
    34         }
    35 
    36         //添加子节点
    37         private string AddChildNode(String text)
    38         {
    39             string sql = "select * from Menu Where MainMenu ='" + text + "'";
    40             DataSql data = new DataSql();
    41             data.DataCon();
    42             DataSet ds = data.GetDataset(sql);
    43             XmlNode root = xmlDoc.SelectSingleNode("/siteMap/siteMapNode/siteMapNode[@title='" + text + "']");
    44             for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
    45             {
    46                 DataRowView row = ds.Tables[0].DefaultView[i];
    47 
    48                 string ChildMenu = row["ChildMenu"].ToString();
    49                 if (ChildMenu != "")
    50                 {
    51                     string NavigateUrl = row["NavigateUrl"].ToString();
    52 
    53                     XmlElement siteMapNode = xmlDoc.CreateElement("siteMapNode");
    54                     siteMapNode.SetAttribute("title", ChildMenu);
    55                     siteMapNode.SetAttribute("description", "");
    56                     siteMapNode.SetAttribute("url", NavigateUrl);
    57                     root.AppendChild(siteMapNode);
    58                 }
    59             }
    60             return text;
    61         }
  • 相关阅读:
    文档生成器
    jenkins多分支版本备份
    jenkins发布控制版本号和同步
    py导出时段报表
    jenkins多分支回滚总结文
    jenkins单分支版本备份
    k8s多pod查询日志脚本
    php 0425
    php 0418
    php 0422
  • 原文地址:https://www.cnblogs.com/varorbc/p/3424888.html
Copyright © 2020-2023  润新知