Go Premium for a chance to win a PS4. Enter to Win

x
?
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
Medium Priority
?
282 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 750 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Screencast - Getting to Know the Pipeline
Suggested Courses

885 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