XmlSiteMapProvider.Initialize(String, NameValueCollection) Method


Initializes the XmlSiteMapProvider object. The Initialize(String, NameValueCollection) method does not actually build a site map, it only prepares the state of the XmlSiteMapProvider to do so.

 override void Initialize(System::String ^ name, System::Collections::Specialized::NameValueCollection ^ attributes);
public override void Initialize (string name, System.Collections.Specialized.NameValueCollection attributes);
override this.Initialize : string * System.Collections.Specialized.NameValueCollection -> unit
Public Overrides Sub Initialize (name As String, attributes As NameValueCollection)



The XmlSiteMapProvider to initialize.


A NameValueCollection that can contain additional attributes to help initialize name. These attributes are read from the XmlSiteMapProvider configuration in the Web.config file.


The XmlSiteMapProvider is initialized more than once.

A SiteMapNode used a physical path to reference a site map file.


An error occurred while attempting to parse the virtual path supplied for the siteMapFile attribute.


The following code example demonstrates how to create a new instance of the XmlSiteMapProvider class and initialize it to build a site map from XML data.

<%@ Page Language="c#" %>  
<SCRIPT runat="server">  
 private void Page_Load(object sender, System.EventArgs e) {  
     // Create an instance of the XmlSiteMapProvider class.  
     XmlSiteMapProvider testXmlProvider = new XmlSiteMapProvider();  
     NameValueCollection providerAttributes = new NameValueCollection(1);  
     // Initialize the provider with a provider name and file name.  
     testXmlProvider.Initialize("testProvider", providerAttributes);  
     // Call the BuildSiteMap to load the site map information into memory.  
     // Prints "/myvirtualdirectory/WebForm1.aspx"  
     Response.Write(testXmlProvider.RootNode.Url + "<BR>");  
     // Prints "/myvirtualdirectory/WebForm2.aspx"  
     Response.Write(testXmlProvider.CurrentNode.Url + "<BR>");  

The preceding code example uses an XML file that is located in the virtual root of the ASP.NET application. The file has the following format:

  <siteMapNode title="RootNode" description="The root page." url="WebForm1.aspx">  
    <siteMapNode title="CurrentNode" description="Some sub page." url="WebForm2.aspx"/>  


The XmlSiteMapProvider class overrides the inherited Initialize method to apply several attributes, such as the siteMapFile and description attributes, to the attributes collection.

Applies to

See also