手机
当前位置:查字典教程网 >编程开发 >C#教程 >c#生成站点地图(SiteMapPath)文件示例程序
c#生成站点地图(SiteMapPath)文件示例程序
摘要:复制代码代码如下://创建站点地图privatevoidCreateSiteMap(DataSetds){XmlDeclarationdec...

复制代码 代码如下:

//创建站点地图

private void CreateSiteMap(DataSet ds)

{

XmlDeclaration declareation;

declareation = xmlDoc.CreateXmlDeclaration("1.0", "UTF-8", null);

xmlDoc.AppendChild(declareation);

XmlElement xeRoot = xmlDoc.CreateElement("siteMap");

xmlDoc.AppendChild(xeRoot);

XmlElement xroot = xmlDoc.CreateElement("siteMapNode");

xroot.SetAttribute("title", "");

xroot.SetAttribute("url", "#");

xeRoot.AppendChild(xroot);

for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)

{

DataRowView row = ds.Tables[0].DefaultView[i];

string MainMenu = row["MainMenu"].ToString();

string NavigateUrl = row["NavigateUrl"].ToString();

if (MainMenu != str)

{

XmlElement siteMapNode = xmlDoc.CreateElement("siteMapNode");

siteMapNode.SetAttribute("title", MainMenu);

siteMapNode.SetAttribute("description", "");

siteMapNode.SetAttribute("url", NavigateUrl);

xroot.AppendChild(siteMapNode);

str = AddChildNode(MainMenu);

}

}

xmlDoc.Save(Server.MapPath("Web.sitemap"));

}

//添加子节点

private string AddChildNode(String text)

{

string sql = "select * from Menu Where MainMenu ='" + text + "'";

DataSql data = new DataSql();

data.DataCon();

DataSet ds = data.GetDataset(sql);

XmlNode root = xmlDoc.SelectSingleNode("/siteMap/siteMapNode/siteMapNode[@title='" + text + "']");

for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)

{

DataRowView row = ds.Tables[0].DefaultView[i];

string ChildMenu = row["ChildMenu"].ToString();

if (ChildMenu != "")

{

string NavigateUrl = row["NavigateUrl"].ToString();

XmlElement siteMapNode = xmlDoc.CreateElement("siteMapNode");

siteMapNode.SetAttribute("title", ChildMenu);

siteMapNode.SetAttribute("description", "");

siteMapNode.SetAttribute("url", NavigateUrl);

root.AppendChild(siteMapNode);

}

}

return text;

}

【c#生成站点地图(SiteMapPath)文件示例程序】相关文章:

c# n个数排序实现代码

c#中返回文章发表的时间差的示例

C# 静态变量与静态方法实例研究

C#生成不重复随机数列表实例

c# 删除所有的空文件夹的小例子

visio二次开发--判断文档是否已发生变化(变化就加星号*)

C# 执行bat批处理文件的小例子

C# 得到某一天的起始和截止时间的代码

c# 调用.bat文件的实现代码

c#解压文件的实例方法

精品推荐
分类导航