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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

810 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