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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

685 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