我手动编写Web.sitemap文件,里面写了一个简单的网络书城的站点地图:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" >
    <siteMapNode url="index.aspx" title="网络书城"  description="网络书城">
        <siteMapNode url="~/Sample1/text1.aspx" title="文学"  description="文学" >
        <siteMapNode url="~/Sample1/text2.aspx" title="小说"  description="小说" />
        <siteMapNode url="~/Sample1/text3.aspx" title="散文"  description="散文" />
    </siteMapNode>
  <siteMapNode url="~/Sample2/text4.aspx" title="工学"  description="杂学">
        <siteMapNode url="~/Sample2/text5.aspx" title="计算机学"  description="计算机" />
        <siteMapNode url="~/Sample2/text6.aspx" title="机械学"  description="机械学" />
    </siteMapNode>
  </siteMapNode>
</siteMap>然后创建一个网页index.aspx;在页面添加SiteMapDataSource控件,ID为SiteMapDataSource1;在页面添加TreeView,ID为TreeView1,设置TreeView1属性DataSourceID为SiteMapDataSource1,代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="index.aspx.cs" Inherits="TreeView控件.index" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
    
    </div>
    <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1">
    </asp:TreeView>
    </form>
</body>
</html>调试运行时报错说XmlSiteMapProvider 所需的文件 web.sitemap 不存在。难道SiteMapDataSource控件不能自动感应绑定Web.sitemap文件中的内容,需要自己创建新的数据源XmlSiteMapProvider 吗?求高手指点。

解决方案 »

  1.   

    Web.sitemap文件 是否放在跟目录下面
      

  2.   

    你是说是否将Web.sitemap文件夹放在index网页文件夹的目录下么
      

  3.   

    lz弄错了吧 <asp:SiteMapPath ID="SiteMapPath1" runat="server" Font-Names="Verdana" Font-Size="0.8em"
                PathSeparator=" : ">
                <PathSeparatorStyle Font-Bold="True" ForeColor="#5D7B9D" />
                <CurrentNodeStyle ForeColor="#333333" />
                <NodeStyle Font-Bold="True" ForeColor="#7C6F57" />
                <RootNodeStyle Font-Bold="True" ForeColor="#5D7B9D" />
            </asp:SiteMapPath>的数据源是Web.sitemap<asp:TreeView ID="TreeView1" runat="server" DataSourceID="XmlDataSource1" ExpandDepth="1" ImageSet="WindowsHelp">
                <DataBindings>
                    <asp:TreeNodeBinding DataMember="mainNode" TextField="title" />
                    <asp:TreeNodeBinding DataMember="Node1" TextField="title" />
                    <asp:TreeNodeBinding DataMember="Node2" TextField="title" />
                </DataBindings>
                <ParentNodeStyle Font-Bold="False" />
                <HoverNodeStyle Font-Underline="True" ForeColor="#6666AA" />
                <SelectedNodeStyle BackColor="#B5B5B5" Font-Underline="False" HorizontalPadding="0px"
                    VerticalPadding="0px" />
                <NodeStyle Font-Names="Tahoma" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px"
                    NodeSpacing="0px" VerticalPadding="1px" />
            </asp:TreeView>
            <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/BookList.xml"></asp:XmlDataSource>
      

  4.   

    Web.sitemap必须放在根目录下面 
     LZ不懂什么叫根目录么
      

  5.   


    <?xml version="1.0" encoding="utf-8" ?>
    <mainNode url="BookLists.aspx?typeid=''" title="图书目录"  description="">
      <Node1 url="HotBookList.aspx" title="畅销排行"  description="" />
      <Node1 url="NewBookList.aspx" title="新书推荐"  description="" />
      <Node1 url="BookLists.aspx?typeid='20,17,35'" title="计算机基础"  description="" >
        <Node2 url="BookLists.aspx?typeid='17'" title="计算机等级考试"  description="" />
        <Node2 url="BookLists.aspx?typeid='35'" title="Window操作系统"  description="" />
      </Node1>  <Node1 url="BookLists.aspx?typeid='1,25,29,16,15,4,22,2,21,31,26'" title="软件开发"  description="" >
        <Node2 url="BookLists.aspx?typeid='1'" title="C#程序设计"  description="" />
        <Node2 url="BookLists.aspx?typeid='31'" title="jsp应用教程"  description="" />
        <Node2 url="BookLists.aspx?typeid='29'" title="ASP.NET程序设计"  description="" />
        <Node2 url="BookLists.aspx?typeid='16'" title="Basic VB VB Script"  description="" />
        <Node2 url="BookLists.aspx?typeid='15'" title="C C++ VC VC++"  description="" />
        <Node2 url="BookLists.aspx?typeid='4'" title="CSS Div"  description="" />
        <Node2 url="BookLists.aspx?typeid='22'" title="HTML XML"  description="" />
        <Node2 url="BookLists.aspx?typeid='2'" title="J2EE应用教程"  description="" />
        <Node2 url="BookLists.aspx?typeid='21'" title="Java Script Java"  description="" />
        <Node2 url="BookLists.aspx?typeid='31'" title="JSP"  description="" />
        <Node2 url="BookLists.aspx?typeid='26'" title="Perl"  description="" />
      </Node1>  <Node1 url="BookLists.aspx?typeid='27,4,22'" title="网页制作"  description="" >
        <Node2 url="BookLists.aspx?typeid='4'" title="CSS实用手册"  description="" />
        <Node2 url="BookLists.aspx?typeid='22'" title="Dreamweaver自学手册"  description="" />
      </Node1>  <Node1 url="" title="其它"  description="" >
        <Node2 url="" title="其它"  description="" />
      </Node1>  <Node1 url="" title="个人信息管理"  description="" >
        <Node2 url="~/MemberShip/UserUpdatepwd.aspx" title="修改密码"  description="" />
        <Node2 url="~/MemberShip/UpdateUser.aspx" title="修改个人信息"  description="" />
      </Node1></mainNode>