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


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.


        /// <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";

        /// <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)

            /* For later use...
             * XmlTextWriter xw = new XmlTextWriter(Application.StartupPath + @"\data.xml", Encoding.UTF8);
            xw.Formatting = Formatting.Indented;
            xw.Indentation = 4;

Please help!


W. Hoefsloot
The Netherlands
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

See this sample for adding menus dynamically

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
WernandAuthor Commented:

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.


Wernand Hoefsloot
The Netherlands
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.