While ASP.NET 2.0 provides a number of controls to implement site navigation, almost all of them depend on a sitemap. A sitemap is simply an XML file (called web.sitemap) that stores the navigational information about the site in a structured format. The ASP.NET navigation controls use this XML file as a source of data to display the information contained in different graphical manners.
SharePoint Designer provides a template file that allows you to start building a web.sitemap file for your Web site. To create a web.sitemap file, choose File New to display the New dialog box. In the ASP.NET section of the Page tab is the Site Map option. The default sitemap file that SharePoint Designer creates has the following code:
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="" title="" description=""> <siteMapNode url="" title="" description="" /> <siteMapNode url="" title="" description="" /> </siteMapNode> </siteMap>
The sitemap XML file needs the <siteMap> element as the root element for the XML structure. Within the <siteMap> element, there needs to be at least one <siteMapNode> element that describes the name, relative URL, and description of the link in the site navigation. Then, you have a </siteMapNode> that helps define the nested navigation links. The following code is a sample XML for the web.sitemap file:
<?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="~/default.htm" title="Home" description="Home Page"> <siteMapNode url="~/InsertingWebComponents.htm" title="Web Components" description="Inserting web components on web pages" /> <siteMapNode url="~/StandardControls.aspx" title="Standard Controls" description="Inserting standard controls" /> </siteMapNode> </siteMap>
The ASP.NET 2.0 controls can now use this web.sitemap file to display the stored navigation. SharePoint Designer makes available the Menu, TreeView, and SiteMapPath controls for use on Web pages.
In the next exercise, you use the TreeView control to display the navigation structure defined in the web.sitemap file for the Web site. To enable the ASP.NET 2.0 controls on a Web page, you need to follow these steps:
Create a web.sitemap file for your Web site.
Insert the TreeView control on the Web page. The Common TreeView Tasks menu is displayed in the Design view, as shown in Figure 10.22.
Using the Choose Data Source dropdown menu, select the SiteMapDataSource control you inserted on the Web page in step 2.
Click the AutoFormat link to open the AutoFormat dialog box and then choose a style for the TreeView control. There are a number of interesting formats to choose from in the AutoFormat dialog box for the TreeView control. You can format the tree to look like a file structure, help file, mailbox, etc.
Similarly, other navigation controls can also be bound to the SiteMapDataSource control to display navigation stored in the web.sitemap file. It's recommended to place the navigation control on a master page so that all the attached Web pages can inherit it.
3.147.36.61