using System; using System.Web; using System.Xml; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { CreateTOC(); } } /// /// Displays the HTML page in a iFrame. /// /// The URL. private void DisplayHtmlPageInIFrame(string url) { //Display page in a iframe iFrame.Text = string.Format("", url); ; } /// /// Creates the TOC sync. /// private void CreateTOC() { string tocPath = Server.MapPath("WebTOC.xml"); GenerateTOC(tocPath); } /// /// Generates and populates the TOC. /// /// The toc path. private void GenerateTOC(string tocPath) { //Load TOC XmlDocument toc = new XmlDocument(); toc.Load(tocPath); //Find out root information XmlNode rootNode = toc.SelectSingleNode("//HelpTOCNode"); string rootTitle = rootNode.Attributes["Title"].Value; string rootUrl = rootNode.Attributes["Url"].Value; //Set information on page Page.Title = rootTitle; DisplayHtmlPageInIFrame(rootUrl); //Setup Root Tree Node tocTree.Nodes.Clear(); TreeNode tNode = new TreeNode(rootTitle, rootUrl); tocTree.Nodes.Add(tNode); //Start recursive call AddNode(rootNode, tNode); tocTree.ExpandAll(); } /// /// Adds the node to the parentTreeNode /// /// The XML node. /// The parent tree node. private void AddNode(XmlNode xmlNode, TreeNode parentTreeNode) { //Check to see if it has any Child Nodes if (xmlNode.HasChildNodes) { foreach (XmlNode node in xmlNode.ChildNodes) { string title = node.Attributes["Title"].Value; string url; if (node.Attributes["Url"] == null) url = "#"; else url = node.Attributes["Url"].Value; //Create node for tree TreeNode newNode = new TreeNode(HttpUtility.HtmlEncode(title), url); //Add node to parent tree node parentTreeNode.ChildNodes.Add(newNode); //Call method again for possible child methods AddNode(node, newNode); } } } /// /// Handles the SelectedNodeChanged event of the tocTree control. /// /// The source of the event. /// The instance containing the event data. protected void tocTree_SelectedNodeChanged(object sender, EventArgs e) { //Display selected node's page DisplayHtmlPageInIFrame(tocTree.SelectedNode.Value); } protected void ExpandAll_Click(object sender, System.Web.UI.ImageClickEventArgs e) { tocTree.ExpandAll(); } protected void CollapseAll_Click(object sender, System.Web.UI.ImageClickEventArgs e) { tocTree.CollapseAll(); } }