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
269 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

920 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

12 Experts available now in Live!

Get 1:1 Help Now