Export (0) Print
Expand All

XmlSiteMapProvider::Initialize Method

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

Namespace:  System.Web
Assembly:  System.Web (in System.Web.dll)

public:
virtual void Initialize(
	String^ name, 
	NameValueCollection^ attributes
) override

Parameters

name
Type: System::String

The XmlSiteMapProvider to initialize.

attributes
Type: System.Collections.Specialized::NameValueCollection

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

ExceptionCondition
InvalidOperationException

The XmlSiteMapProvider is initialized more than once.

HttpException

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

- or -

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

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

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);
     providerAttributes.Add("siteMapFile","test.sitemap");
 
     // 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.
     testXmlProvider.BuildSiteMap();

     // Prints "/myvirtualdirectory/WebForm1.aspx"
     Response.Write(testXmlProvider.RootNode.Url + "<BR>");

     // Prints "/myvirtualdirectory/WebForm2.aspx"
     Response.Write(testXmlProvider.CurrentNode.Url + "<BR>");
 }
 </SCRIPT>

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:

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft