Solved

how to Recursively write the different menuItems to a xml file, and in a later phase read this xml file and recreate the mainmenu

Posted on 2004-09-12
2
268 Views
Last Modified: 2010-04-15
Hi,

Is there a way to write the recursions mainmenu results down in a xml file with XmlTextWriter, and then reading this xml file (in a later phase) and (re)create this mainmenu whit the xml data.

I am trying to make this, for several weeks but I am stuck with it.

script:

        /// <summary>
        /// Recursively get the different MenuItems
        /// </summary>
        /// <param name="menu"></param>
        private void RecursivelyGetMenuItems(Menu menu)
        {
            foreach (MenuItem mi in menu.MenuItems)
            {
                // TextBox:
                txtInfo.Text += mi.Text + "\r\n";

                if (mi.IsParent)
                {
                    txtInfo.Text += "Parent: " + mi.Text + "\r\n";
                    this.RecursivelyGetMenuItems(mi);
                }
            }
        }

        /// <summary>
        /// Button to write the mainmenu contents to a xml file
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnWriteXml_Click(object sender, System.EventArgs e)
        {
            this.RecursivelyGetMenuItems(mainMenu1);

            /* For later use...
             *
             * XmlTextWriter xw = new XmlTextWriter(Application.StartupPath + @"\data.xml", Encoding.UTF8);
            xw.Formatting = Formatting.Indented;
            xw.Indentation = 4;
            xw.WriteStartDocument();
            xw.WriteStartElement("root");
            xw.WriteStartElement("XmlData");
            xw.WriteEndElement();
            xw.WriteEndElement();
            xw.WriteEndDocument();
            xw.Close();
           
            */
        }

Please help!

Regards,

W. Hoefsloot
The Netherlands
0
Comment
Question by:Wernand
2 Comments
 
LVL 18

Accepted Solution

by:
armoghan earned 250 total points
ID: 12041268
See this sample for adding menus dynamically

http://www.codeproject.com/cs/menu/csdynmenudemo.asp
0
 

Author Comment

by:Wernand
ID: 12042829
Thanks,

There is at the bottom of this article an update from Martin Robins. This is not so complex as the article of Marc Clifton. But the addition of Martin Robins, is helpfully to me.

Regards,

Wernand Hoefsloot
The Netherlands
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now